Sign in to follow this  

[ODE] Shooting cube - direction

This topic is 2049 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm trying to shoot cube with direction = direction where player is looking,

[CODE]
vector3df ray = sceneCamera->getPosition() + ( sceneCamera->getTarget() - sceneCamera->getPosition() ).normalize() * 1000.0f;
ray *= speed;
tmpNode->setLinearVelocity( vector3df( ray.X, ray.Y, ray.Z ) );
[/CODE]

tmpNode->setLinearVelocity is alias to dBodySetLinearVelocity.

Direction is almost, almost ok... I dunno' what I've did wrong. Thanks

Share this post


Link to post
Share on other sites
It should look like:
[code]
( sceneCamera->getTarget() - sceneCamera->getPosition() ).normalize() * 1000.0f
[/code]

Because the difference between two positions is the distance between them, normalizing it brings the direction, multiplying by a scalar returns a direction with speed. Adding it to sceneCamera->getPosition() is another position, yet it is interpreted as a direction with speed. Edited by fastcall22

Share this post


Link to post
Share on other sites

This topic is 2049 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this