Rick Posted January 20, 2010 Share Posted January 20, 2010 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. Quote Link to comment Share on other sites More sharing options...
Rick Posted January 25, 2010 Author Share Posted January 25, 2010 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. Quote Link to comment Share on other sites More sharing options...
Sooshi Posted January 25, 2010 Share Posted January 25, 2010 I agree, I have already ran accross this problem and even asked Rick for advice, does anyone know a way to solve this problem? Quote Working on a major RPG project.......will showcase soon. www.kevintillman1.wix.com/tillmansart Link to comment Share on other sites More sharing options...
Josh Posted January 26, 2010 Share Posted January 26, 2010 This is contrary to the design of associating a script with a model entity. What are you creating bodies for? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Niosop Posted January 26, 2010 Share Posted January 26, 2010 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. Quote Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
Rick Posted January 26, 2010 Author Share Posted January 26, 2010 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. Quote Link to comment Share on other sites More sharing options...
Josh Posted January 27, 2010 Share Posted January 27, 2010 Maybe we can set a Lua function name the same way we set an entity collision callback. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted January 27, 2010 Author Share Posted January 27, 2010 Do you mean like a predefined global function name that if we define in lua will get called when a collision happens? Quote Link to comment Share on other sites More sharing options...
Josh Posted January 27, 2010 Share Posted January 27, 2010 Yes, and the body would be passed to it, the same way a collision callback in C works. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted January 27, 2010 Author Share Posted January 27, 2010 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. Quote Link to comment Share on other sites More sharing options...
Josh Posted January 27, 2010 Share Posted January 27, 2010 Note that in Lua, if a function isn't declared yet, it doesn't exist: function myluafunc(...) end SetEntityCallback(body,"myluafunc",ENTITYCALLBACK_COLLISION) Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted January 27, 2010 Author Share Posted January 27, 2010 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. Quote Link to comment Share on other sites More sharing options...
Josh Posted January 27, 2010 Share Posted January 27, 2010 Whoops, that is true. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
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.