Hi All,
I am trying to 'simply' have a cube that I can 'steer' across a landscape.
I'm very confused on which method I should use to do this impulse/linear etc.
How do I know it's direction facing and move in that direction?
Currently with (for example) linearvelocity the cube will move in the correct direction but has no sense of 'the front' and also tumbles etc. whilst I require it to stay up the correct way.
I've tried reducing friction and increasing it's mass to solve this problem but to no effect.
Any pointers much appreciated.
Thanks
p.s. do not want to use a complex vehicle model just a cube.
Simple 'driving' demonstration
-
- Posts: 39
- Joined: Sat May 02, 2009 9:38 am
Re: Simple 'driving' demonstration
Let's assume your "front" direction is btVector(1, 0, 0). You have to get body's btTransform. Then you get the front direction like this:markhula wrote:How do I know it's direction facing and move in that direction?
btVector3 frontDir = transform*btVector(1, 0, 0);
You then apply central force, which is computed like this:
frontForce = frontDir*btScalar(myForce);
-
- Posts: 34
- Joined: Thu Jun 17, 2010 10:11 am
Re: Simple 'driving' demonstration
Thanks for your help.
I am stuck on the last step; how I actually 'apply' the force on the basis that I have :
btVector3 front(1.0f,0.0f,0.0f);
btTransform trans=obj->_SIO2objectphysic->_btRigidBody->getWorldTransform();
btVector3 facing=trans*front;
btVector3 frontForce = facing*btScalar(dist_y);
obj->_SIO2objectphysic->_btRigidBody->applyCentralImpulse(frontForce);
It doesn't seem to move hardly at all; and not in the correct direction.
Can you please give further detail?
Thanks
I am stuck on the last step; how I actually 'apply' the force on the basis that I have :
btVector3 front(1.0f,0.0f,0.0f);
btTransform trans=obj->_SIO2objectphysic->_btRigidBody->getWorldTransform();
btVector3 facing=trans*front;
btVector3 frontForce = facing*btScalar(dist_y);
obj->_SIO2objectphysic->_btRigidBody->applyCentralImpulse(frontForce);
It doesn't seem to move hardly at all; and not in the correct direction.
Can you please give further detail?
Thanks
-
- Posts: 34
- Joined: Thu Jun 17, 2010 10:11 am
Re: Simple 'driving' demonstration
Ok, I do this but it's still wrong, I can't see why.
btQuaternion qt;
qt.setEuler(0,0,angle);
obj->_SIO2objectphysic->_btRigidBody->getWorldTransform().setRotation(qt);
btVector3 relativeForce = btVector3(-dist_x,-dist_y,0);
btMatrix3x3& boxRot = obj->_SIO2objectphysic->_btRigidBody->getWorldTransform().getBasis();
btVector3 correctedForce = boxRot * relativeForce;
obj->_SIO2objectphysic->_btRigidBody->applyCentralForce(correctedForce);
I think my 'steering' is wrong. I need to "applyforce" on my orientation; tried setangularvelocity but this doesn't seem to work as I would expect.Also my relativeForce isn't taking in the direction facing either.
Appreciate any more pointers you can give on this.
Thanks
btQuaternion qt;
qt.setEuler(0,0,angle);
obj->_SIO2objectphysic->_btRigidBody->getWorldTransform().setRotation(qt);
btVector3 relativeForce = btVector3(-dist_x,-dist_y,0);
btMatrix3x3& boxRot = obj->_SIO2objectphysic->_btRigidBody->getWorldTransform().getBasis();
btVector3 correctedForce = boxRot * relativeForce;
obj->_SIO2objectphysic->_btRigidBody->applyCentralForce(correctedForce);
I think my 'steering' is wrong. I need to "applyforce" on my orientation; tried setangularvelocity but this doesn't seem to work as I would expect.Also my relativeForce isn't taking in the direction facing either.
Appreciate any more pointers you can give on this.
Thanks
-
- Posts: 39
- Joined: Sat May 02, 2009 9:38 am
Re: Simple 'driving' demonstration
Oh, sorry!
this
btVector3 facing=trans*front;
should be like this
btVector3 facing=trans.getBasis()*front;
Because you do not want to use the translation part of the transform, just rotational.
If you want to rotate the body, try applying central torque whose vector should be facing upwards.
this
btVector3 facing=trans*front;
should be like this
btVector3 facing=trans.getBasis()*front;
Because you do not want to use the translation part of the transform, just rotational.
If you want to rotate the body, try applying central torque whose vector should be facing upwards.
-
- Posts: 34
- Joined: Thu Jun 17, 2010 10:11 am
Re: Simple 'driving' demonstration
Thanks!
Will try it.
Appreciated
Will try it.
Appreciated