Moving an actor object

jeremywilms

03-12-2009 06:00:31

Is there anyway to move an actor object, however, having it effected by the environment, I.e walking up and down slopes, having the height change? I was thinking about using force, but to do this when trying to control a player could be difficult.

LucaMoller

03-12-2009 15:30:17

In my fighting game I did it the following way: I created a big capsule to represent the character as a moving object. I did not use the kinematic flag, it is a dynamic object! To prevent it from rotating, I aplied the rotation lock flags (it wont rotate naturally, to do it you have to setOrientation() ). Now, when I wanted them to move or jump, I set a velocity in the right direction. As my enviroment shape is represent by a triangle mesh the capsule will be affected by it the way you want.

obs: You might have to change the physics material of the objects. I remenber that friction made weird things in this system I suggested, so I used materials with no friction between the capsule and the cenario and made an artificial friction force (that made the capsule slow down when its touching the floor). I have some tricks to detect when a character can jump or not if you are interested. (you know, you wont want your character to be albe to jump if it is only in touch with a wall, you would like it to be able to jump when its foot is touching the floor)

jeremywilms

03-12-2009 19:15:44

In my fighting game I did it the following way: I created a big capsule to represent the character as a moving object. I did not use the kinematic flag, it is a dynamic object! To prevent it from rotating, I aplied the rotation lock flags (it wont rotate naturally, to do it you have to setOrientation() ). Now, when I wanted them to move or jump, I set a velocity in the right direction. As my enviroment shape is represent by a triangle mesh the capsule will be affected by it the way you want.

obs: You might have to change the physics material of the objects. I remenber that friction made weird things in this system I suggested, so I used materials with no friction between the capsule and the cenario and made an artificial friction force (that made the capsule slow down when its touching the floor). I have some tricks to detect when a character can jump or not if you are interested. (you know, you wont want your character to be albe to jump if it is only in touch with a wall, you would like it to be able to jump when its foot is touching the floor)


Thank you very much for this, I have to restructure a bit of my physics wrapper(wrapping NxOgre) to do this, but it should strengthen it a ton.

For detection of jumping, I was thinking of raycasting downwards, if distance was 0, a jump was executed. However, I'm interested to hear your technique.

LucaMoller

04-12-2009 04:08:19


For detection of jumping, I was thinking of raycasting downwards, if distance was 0, a jump was executed. However, I'm interested to hear your technique.


I create another smaller capsule with smaller radius and place it with a fixed joint in the foot of the big one. When this capsule colides with the ground I set a able_to_jump variable true (in the on_start_touch and on_touch) and in the on_end_touch I set it false. This way, the able_to_jump will be true only when the bottom part of your character is touching the cenario. If your character is just touching a wall of the cenario, the able_to_jump will be false, since the new capsule has smaller radius only the big capsule will be on touch with the wall.

About the raycasting, I imagine that it should work fine too. (I never used raycasts yet, since I dont have much experience with physics and 3d engines. My only experience in this area until now was my fighting game, it was like learning and doing at the same time xD )

jeremywilms

05-12-2009 23:06:22

Thanks. I'll probably stick with raycasting, I don't want to directly use NxOgre in my game, if I wan't to switch out physics wrappers, or use another physics engine it could be hell if I tightly integrate it.

I'm having a bit of a problem though with moving the character. I've surrounded him with a capsule that fits him well, locked the rotation axis, however, when I want to move him I'm using the addTorque function in the Actor object. Problem is, he slides along the floor when I don't want him walking.

LucaMoller

06-12-2009 15:02:05

I think it is useless to addTorque after you locked the axis from rotation (I think the only way to rotate the object now is using setOrientation() or setGlobalOrientation() ). I just rotate my charaters in one plane, the one parallel to the floor, to do so I used Quaternions like
( cos(theta/2 ), 0 , sen(theta/2), 0 ). After putting them with the right orientation I use setLinearVelocity to move them in the direction I want.

jeremywilms

06-12-2009 20:37:19

If I use setLinearVelocity, it doesn't work, because the velocity set by the physics engine(To push it out of the way of an object when it has collided, or apply gravity, differs, so I can just walk through objects.) .