smashthewindow Posted January 6, 2012 Share Posted January 6, 2012 I've been trying to create the controller class in Leadwerks to C++. The frequency of collision callback getting called seems to be random - in some frames they are called once, in some frame several times. So say that I have a boolean function that is set to true on collision callback function, and I do my jump if the boolean is set to true. I'm not sure where I should be setting that boolean to false, beginning of every frame gives me false-positives. Anyone shed some light on this? Quote Blog & Portfolio Current project: moon.chase.star Link to comment Share on other sites More sharing options...
Andr3wHur5t Posted January 16, 2012 Share Posted January 16, 2012 Sence you are using a class we dont want to use a bool because if you make it a public member you still wont have acsess to it in the callback,or if you made it a global you would have to create a system to keep track of wich bool went to which Controller you can eather make a struct and put it in EntityUserData or use EntityKeys I will use EntityKeys this is just off of the top of my head; not sure if will compile. #include "engine.h" #include "Class_Name.h" //Collision Callback void _stdcall Controller_Collision_Callback( TEntity entity0, TEntity entity1, byte* position, byte* normal, byte* force, flt speed){ //if our controller exists if(EntityExists(entity0)==1){ //Set Jump to 1 SetEntityKey(entity0,"Jump","1"); } } //Constructor Class_Name::Class_Name(){ //Create controller TBody Controller = CreateBodyBox(1,2,1); //Set Proproties //Collision type EntityType(Controller,3); //Mass EntityMass(Controller,10); //Set Collision Callback to Controller_Collision_Callback EntityCallback(Controller,(byte*)Controller_Collision_Callback,ENTITYCALLBACK_COLLISION); } //Call this function every time you want to update the controller void Class_Name::Update(){ //Check if Controller Exists if(EntityExists(Controller)){ //Check Jump if(GetEntityKey(Controller,"Jump","NULL")=="1"){ //Make The Controller Jump SetBodyForce(Controller,Vec3(0,100,0)); //Reset the Jump Key SetEntityKey(entity0,"Jump","0"); } } } Class_Name::~Class_Name(){ //Free controller FreeEntity(Controller); } Quote Tools: AC3D | 3D Canvas(pro) | Texture Maker(pro) | Genetica(basic) | 3D World Studio | Fragmotion |Leadwerks 2 | XNA 4 | Visual Studio 2010 Professional | XCode 5.x |UU3D Pro Programing & Scripting Languages: C |C++ | C# | Obj-C | LUA | Javascript | PHP | Ruby Link to comment Share on other sites More sharing options...
Josh Posted January 16, 2012 Share Posted January 16, 2012 I've been trying to create the controller class in Leadwerks to C++. The frequency of collision callback getting called seems to be random - in some frames they are called once, in some frame several times. So say that I have a boolean function that is set to true on collision callback function, and I do my jump if the boolean is set to true. I'm not sure where I should be setting that boolean to false, beginning of every frame gives me false-positives. Anyone shed some light on this? The physics system does not necessarily get updated every frame. It gets updated 60 times per second, and entity matrices are interpolated between the last two frames of data calculated, to make everything smooth. 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...
smashthewindow Posted January 16, 2012 Author Share Posted January 16, 2012 The physics system does not necessarily get updated every frame. It gets updated 60 times per second, and entity matrices are interpolated between the last two frames of data calculated, to make everything smooth. Thank you, I've been thinking that's what happens but it clears a lot for me Quote Blog & Portfolio Current project: moon.chase.star 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.