Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: A physics engine question.  (Read 640 times)
nico2008
Community Member
*
Posts: 42


« on: July 29, 2011, 01:05:25 AM »

I want to make a man move in game and collide with box,
so I add box and man in the physics engine.
I  use TVPhysics.SetBodyLinearVelocity() to make actor move forward,But his angle would change in the same time.
And when the angle is changing,I cant get the right direction for moving,
angle=TVP.GetBodyRotation(body).y
TVP.SetBodyPosition(body,x+10*Cos(angle),y,z+10*Sin(angle))
so the body will move for other direction.I dont know why the angle will change,and I cant get another way to achieve this goal.So help me.
Logged
asia
Customers
Community Member
*****
Posts: 183


« Reply #1 on: July 29, 2011, 08:32:50 AM »

Check the unit used for the angle. Did you mix up radiants and degrees?
The cos function works in radiants while, by default, the TV angles are in degrees.
Logged

Fabio Musmeci
ENEA
CR Casaccia
Via Anguillarese 301
00060 Rome
Italy
musmeci@enea.it
+39 3333934898
Learning to live better on a smaller footprint..
nico2008
Community Member
*
Posts: 42


« Reply #2 on: July 29, 2011, 04:32:20 PM »

thanks for your reply.
I can sure the angle system is ok.
For example,the angle is 20,it will change between 18-22,not very big change,but it make model move in a wrong direction.
I hope u can  personal test ,then tell me whether u suffer this situation。thanks
Logged
Mithrandir
Community Member
*
Posts: 325


« Reply #3 on: July 30, 2011, 08:51:04 AM »

When you run the physics the position, rotation, velocities and external forces acting on a body are calculated by the engine. So if you just set the position you only move the body but the angular velocity keeps changing the rotation. Especially if you collide with the environments your body can start rolling around the obstacle thus changing Y angle. Render the physics debug meshes to see what's going on.

You could actually ignore the body Y rotation completly. Just use the rotation of the camera (which you change using mouse or otherwise) and use this angle to move the body around (instead of the body rotation).

Also, use forces and torques to move the body around. You will have to calculate the appropriate force to apply but you get all the benefits of the physics engine (collisions, interactions, gravity, etc). SetBodyPosition does not do any collision checking for you.
Logged
nico2008
Community Member
*
Posts: 42


« Reply #4 on: July 30, 2011, 12:54:54 PM »

Great thanks to Mithrandir.I think I have a result for this problem.
The way your provided I think is enough to solve my problem,thX. Smiley
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks