• Advertisement
Sign in to follow this  

Irrlicht - FPSish weapon placement

This topic is 3376 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 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;

gun->setPosition(GunRenderPosition);
gun->setRotation(GunRotation);


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
Advertisement
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.SetPosition( ROCKETLAUNCHER_POSITION_OFFSET );
LauncherModel.SetRotation( ROCKETLAUNCHER_ROTATION_OFFSET );

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
Sign in to follow this  

  • Advertisement