Jump to content

Collision detection


smashthewindow
 Share

Recommended Posts

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?

Blog & Portfolio

 

Current project: moon.chase.star

Link to comment
Share on other sites

  • 2 weeks later...

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);
}

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

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.

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

 

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 :)

Blog & Portfolio

 

Current project: moon.chase.star

Link to comment
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.

 Share

×
×
  • Create New...