Sign in to follow this  

Irrlicht - FPSish weapon placement

Recommended Posts

Hi everyone! I'm messing arond a bit with Irrlicht, trying to load in a mesh (a gun) and placing it in front of a user controlled camera, first person shooter style. So far, I've managed place the weapon at the camera coordinates, and making it follow the camera when looking around. This of course makes the player walking around "inside" the weapon, so it need to be moved slightly in front of the camera. This is what I've done:
vector3df CameraPosition = camera->getPosition();
vector3df CameraRotation = camera->getRotation();

vector3df GunPosition = CameraPosition;
vector3df GunRotation = CameraRotation;

vector3df Direction = CameraRotation.normalize();
Direction *= 0.2f; // offset to be figured out

vector3df GunRenderPosition = GunPosition + Direction;


First of all, am I in the ballpark here? When offset is around 0.2f, the weapon seems to follow correctly, it just needs to be tweaked, but when I increase the offset too much, the weapon ends up above me and stuff. Thank you in advance. - Daniel EDIT: code [Edited by - danieliskogen on October 21, 2008 4:11:50 PM]

Share this post

Link to post
Share on other sites
You will find ISceneNode::setParent() very helpful.

Here's how i did it, the offsets will vary.

#define ROCKETLAUNCHER_POSITION_OFFSET vector3df( -1.5f, 3.5f, -2.5f )
#define ROCKETLAUNCHER_ROTATION_OFFSET vector3df( 0.0f, -90.0f, -4.0f )

void RocketLauncher::AttachTo( MainPlayer& Player )

LauncherModel.SetParent( Player.GetCamera().GetSceneNode() );

LauncherModel.GetSceneNode()->setMaterialFlag( EMF_LIGHTING, false );

Share this post

Link to post
Share on other sites
Yes, that's how scene graphs works. If you haven't then I recommend you to read some information about them. They can be very useful.

Share this post

Link to post
Share on other sites

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