Another one on character control and some ideas.

HexDump

07-01-2008 08:21:56

Hi all,

After being playing around with ogrenewt (about 1 week), I have reached to the conclusion that I prefer not to use physics on Characters user can control, and perhaps in some type of enemies. This are my ideas (some I can´t yet accomplish, so this is why I posted):

1) I would like to leave player out of the simulation (just use collision detection).
2) If I need any special effect like player throwing, good dying effect, etc... I will add it again to the simulation, and perhaps delete de rigid body and create a rag doll.
3) I thought I could accomplish this through the freeze() function, moving myself the rigid body, but it seems collision detection does not work if the body is freezed.

So, with this ideas, could anyone tell me if I can get what I need? The main idea is, polish character behaviour with physics for my game is difficult, so, why not just use physics when really needed? but mantaining the help of collision detection?.

Thanks in advance,
HexDump.

walaber

07-01-2008 18:02:28

the easiest thing to do is to create a rigid body for your character, and set the friction between it and the world to zero, so it slides easily.

then use the setVelocity and setOmega to move and rotate the object however you want. this will allow collision detection to still happen, but you can directly control the movement of the object.

the side effect is that this makes the player infinitely "strong", so it will be able to push any object out of its way, regardless of mass.

HexDump

08-01-2008 14:21:38

Walaber is it possible to check collisions myself? I mean, can I with newton create a body, freeze it (for example), and query myself for collision of this body against other? or the world?. I think this is good way to go, I will have my enemies and players check for collisions from logic code and all the other things in the game let the physics take care of them.

thanks for your help mate,
HexDump.

walaber

08-01-2008 17:27:12

yes, but if you want to check all collisions against a particular object manually, you can do it 2 ways.

1. do NOT create a Body object, just create the Collision object, and call the low-level collision checks yourself.

2. create a Body, and set it to a special material, that has a collision callback for it vs. all other materials. in the collision callback, record the collision, and return zero, to tell Newton to ignore the collision. then in your own code you can check the collision data you stored in the callback, and handle it however you like. this is the more powerful way, because it uses Newton's internal structures to efficiently test for collision, but will make sure that Newton doesn't "move" your Body in any way.

HexDump

08-01-2008 21:34:21

Good point walaber... I just added a collision system for my game, so I think I will go for second option. This way, I will be able to control my character just using for example Body->setPositionRotation, I can use here a simple collision for example a box or a sphere that I can change later to a ragdoll, etc... if it dies, and keep the newton collison system. I think this is the best aproach for me.


Thanks for the answer walaber (as allways),
HexDump.

HexDump

09-01-2008 22:26:00

walaber, just another question. With the second option you exposed, for example if the player touches a bottle in the floor, I should apply a force to the botle depending on its mass (I think this is authomatically done by newton if I return true in the collsion callback) don´t I? I mean, I must control effects of collsions with player myself, applying forces myself on the objects the player collides, am I right?.

Thanks in advance,
HexDump.

walaber

09-01-2008 23:29:40

that's the best part of option 2...

inside the contact callback, you can check what your player is hitting. if the object is a lightweight prop, you can simply return "1" from the function, and let Newton handle the collision. but if the object is something special that you want to handle on your own, you can return "0", and Newton will ignore the collision, and then you can use your own code to do whatever you want.

you can use it like a "collision filter" to control when and how objects interact with each other.

HexDump

10-01-2008 14:22:56

Yes walaber I understood that, the problem is that if I return 1 from the callback, won´t newton move my character?, I mean if I tell newton there was a collision then newton will move both bodies accordly, and this is not whay we want, we want to fully control our character, this is why I told you to return just false from the callback and apply a force on the object the player collide, don´t know if I´m missing something.

On the other hand, I´m being notifying now that a collision occurred with my world (just tiles), how can I know how much I should fix the player position to put it again on the floor? (it is now a bit inside the tile). Must I use a ray cast or something?.


Thanks in advance,

HexDump.