Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

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.

Link to post
Share on other sites

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.

Link to post
Share on other sites

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.

Link to post
Share on other sites

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.

Link to post
Share on other sites

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.

Link to post
Share on other sites

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.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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...