Jump to content
Rick

body collision functions in lua

Recommended Posts

Can we get a way to get some kind of collision method called on physics bodies that we create in lua script? I feel like this is kind of a big deal. I have dynamic sized physics bodies in lua and I need to know when things collide with them.

Share this post


Link to post

Just curious if there was any ideas on this? Either from the community or from Josh. If someone codes just using the main lua file or creates bodies inside using lua code, it doesn't seem like there is any way to get a collision function callback called via lua. Any bone would be nice.

Share this post


Link to post

I agree, I have already ran accross this problem and even asked Rick for advice, does anyone know a way to solve this problem?

Share this post


Link to post

This is contrary to the design of associating a script with a model entity. What are you creating bodies for?

Share this post


Link to post

Last I heard he wanted to create arbitrarily sized platforms via a Lua Thingoid that the Player Controller could stand on. Since we can't scale physics bodies, generating a .phy for them is out, but since he can't get collision callbacks on a Lua created one he's kind of stuck.

Share this post


Link to post

This is contrary to the design of associating a script with a model entity. What are you creating bodies for?

 

 

Like Nio said, things can be more dynamic this way. Also, if you allow a main game lua file, like fpscontroller.lua, then people would expect to treat that just like if you were writing a C++/BMax program and with those you can create bodies and assign a collision callback method.

 

I guess I wouldn't see it as contrary, I would see it as supplementary. The C++ tutorials would be more transferable if we had this. I know Kevin was looking at the bodies tutorial and ran into this issue. He was creating bodies in his main lua file and was asking me how he could get the collision callback working. Currently there is no way. If allowing bodies to be created from lua code, I would think there should be a way to create a callback in lua code when those bodies collide.

Share this post


Link to post

Maybe we can set a Lua function name the same way we set an entity collision callback.

Share this post


Link to post

Do you mean like a predefined global function name that if we define in lua will get called when a collision happens?

Share this post


Link to post

Yes, and the body would be passed to it, the same way a collision callback in C works.

Share this post


Link to post

I think if it was setup just like the C++ callback it would be ideal. We have a function to define that we want this body to have a collision callback called on it. I guess the only difference would be that we don't define the lua function to call, or could we? Ideally we would be able to define the lua function that gets called for each body just like in C++.

 

SetCallback(body, myluafunc, COLLISION);

function myluafunc(...)
end

 

 

If that's to much, then 1 main predefined function would work also.

Share this post


Link to post

Note that in Lua, if a function isn't declared yet, it doesn't exist:

 

function myluafunc(...)
end

SetEntityCallback(body,"myluafunc",ENTITYCALLBACK_COLLISION)

Share this post


Link to post

That's true, but in this case we are only sending the function name as a string back to the engine. As long as the lua function is defined before the physics update all will be good because when the function should be fired from the engine, you can do that with the string of the function name.

 

If doing it from C++ an example would be:

 

/* the function name */
lua_getglobal(L, "add");

/* the first argument */
lua_pushnumber(L, x);

/* the second argument */
lua_pushnumber(L, y);

/* call the function with 2
   arguments, return 1 result */
lua_call(L, 2, 1);

 

Notice how the string "add" is the lua function name.

 

So if we were able to define our own lua functions per body, I assume you could use the exact same code you do for C function pointers but instead you are just storing strings of the lua function names instead of C function pointers.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...