Rotate Model

Hi all!



I'm working on a game with some guns. I want to implement a sniper right now. I already have the sniperscope. I have also modelled a bullet. I want that bullet to be faced to the direction of the camera, so, that if you shoot, the bullet goes to where you aimed at. With other words, the bullet has to lay on the vector3f of cam.getDirection();. I know that you normally don't use a modelled bullet, but a ray to see if you hitted something. But i wan't to make a realistic sniper, whose bullets are affected by wind, gravity… and stuff… I've searched the forum, but I can't find what I'm looking for.

Say your bullet is a Spatial called bullet,

then just put this into your update method:


Quaternion q = new Quaternion();
q.fromAxes(cam.getLeft(), cam.getUp(), cam.getDirection());
bullet.setLocalRotation(q);



Oh, by the way, if you want your sniper to be that real, you should consider that the barrell is not parallel to the scope.

This would be quite important if you want your bullet to be affected by gravity and have a parabolic flying curve..
tim8dev said:

Say your bullet is a Spatial called bullet,
then just put this into your update method:


Quaternion q = new Quaternion();
q.fromAxes(cam.getLeft(), cam.getUp(), cam.getDirection());
bullet.setLocalRotation(q);



Oh, by the way, if you want your sniper to be that real, you should consider that the barrell is not parallel to the scope.

This would be quite important if you want your bullet to be affected by gravity and have a parabolic flying curve..


Thanks, your post was realy helpfull! But I needed to swap the arguments like this:

q.fromAxes(cam.getUp(), cam.getDirection(), cam.getLeft());


because otherwise, my bullet flew vertical. Maybe are the pictures more clear:

Before I swapped


Afterwards:

Thank you very much! And I still have to do a lot of research:-) Thanks for the tip:-)

looks good, just make sure to sent the projective rather than the entire bullet downrange :wink: