Jump to content

Crouch/Ironsighting


ChudStuddley
 Share

Recommended Posts

Hi I am not very experienced at all with Lua/Programming, would it be possible for anyone to help me with steps or a small tutorial even on adding in crouching functionality and iron-sighting to the default FPS/FPSWeapon scripts? I tried my own at the Crouching one by editing somethings and even tried converting over the old FPS controller from Leadwerks 2 but it had some errors and I reversed the changes.

 

Thanks in advance for any help provided!

 

P.S I understand the iron-sighting may or may not come down to animations in the gun itself, if that is the case then if you could explain loading a gun/animations in Lua or point me to somewhere that would help me out more I could just use some FPS Creator weapons. Sorry about the wall-of-text by the way!

Link to comment
Share on other sites

When I was in the FPS script that comes with 3.1 I noticed some crouch code commented out. Not sure why they didn't add it, but did you see that also and is that what you were looking at? I could give this a go, but I won't be home for 10 more hours.

 

By iron-sighting I assume you mean some effect like: http://upload.wikimedia.org/wikipedia/commons/4/4d/Visierlinie.jpg

 

You would have to position the model just right and then use blur post processing script (I think) to blur things close to the camera. Post processing scripts aren't here yet but they will be a part of 3.1 as far as I understand.

  • Upvote 1
Link to comment
Share on other sites

When I was in the FPS script that comes with 3.1 I noticed some crouch code commented out. Not sure why they didn't add it, but did you see that also and is that what you were looking at? I could give this a go, but I won't be home for 10 more hours.

 

By iron-sighting I assume you mean some effect like: http://upload.wikimedia.org/wikipedia/commons/4/4d/Visierlinie.jpg

 

You would have to position the model just right and then use blur post processing script (I think) to blur things close to the camera. Post processing scripts aren't here yet but they will be a part of 3.1 as far as I understand.

Yeah I did see the crouching part was just comments so I tried to see if it worked by un-commenting it (sounds weird lol) to no avail, and yes that is a effect that I want to achieve but without the blur, I just prefer being able to aim down my gun, while not entirely realistic in sight due to usually having the gun incredibly close to the camera, it's a nice effect and common in FPS games nowadays.

Link to comment
Share on other sites

I added the crouching behaviour in the tutorial file during development but josh didnt want to use it for the tutorials.

Is that why it's in a commented section as opposed to code? If so, how come taking away the -- doesn't enable it, is it unfinished/waiting for a update to leadwerks or something?

Link to comment
Share on other sites

For iron sights, you can use a couple Vec3 or Mat4 to represent a m_weaponOffset and m_weaponOffsetRotation while idle and while aiming. you could then use Math::Curve(..) to interpolate between the offsets to allow a smooth transition between the two positions/rotations.

 

For crouching, you can have a bool m_isCrouching value to indicate if the player is crouching, say if Key::ControlKey is pressed. If the player is crouching you set something like m_playerHeight to something like m_crouchHeight and position your camera accordingly.

 

My code is in C++ but I am sure it can easily be translated to Lua.

 

crouching ex.

 

// Check for crouching.
m_isCrouching = window->KeyDown(Key::ControlKey);
// Set height appropriately
SetHeight(( m_isCrouching ? m_crouchHeight : m_standHeight));
// Get a pointer to the game's camera
Camera* gameCamera = GetCamera();
// Get the existing camera's position
Vec3 newCamPos = gameCamera->GetPosition();
// set the new camera position and smooth the y-Position
newCamPos = Vec3(GetPosition().x, Math::Curve(GetPosition().y + GetHeight(), gameCamera->GetPosition().y, m_viewSmoothing), GetPosition().z);
// apply the final results to the viewing camera
gameCamera->SetPosition(newCamPos);

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...