How to disable aiming while sprinting?

Hello everyone by following tutorials I’ve got my aiming and sprinting setup and in the tutorial it showed how to stop the character from sprinting while aiming. The problem I’m having is doing the opposite which is stopping aim while sprinting. When I sprint and click the aim button it zooms in while still doing the sprint animation and when I let everything go the character goes into the aim animation when it should be the normal idle/walk animation.

Hey MTV2223! Welcome back to the forums!

Would you mind posting some screenshots of your code so we can see what you’ve got going on? That way we might be able to suggest an accurate fix!

Get us some more info and we’ll get you taken care of quick! :slight_smile:

Sorry for the late response I just got home from work thank you for the help! I’m having an issue uploading the screenshots because it’s saying im a new user.


1 Like

Cool I got a badge and got to post here is what im working with.

So you should get an “Is Sprinting” bool made, just like your aim. Then, on “pressed” on Input Action Aim, you have two choices.

Directly after Input Action Aim, you can have a branch node checking if sprinting is true, then if sprinting is TRUE: run a custom event as if you released the sprint key before leading into the aim code. This will set move speed to normal, stop your sprinting, then continue the code starting with Set: Is Aiming? = TRUE. The FALSE path off the branch would just lead straight into Set: Is Aiming? and continue on.

The other choice would be if you don’t want to be able to aim cancel your sprint. To do this just put a check after the Input Action Aim for Is Sprinting?, and on TRUE do nothing, and on FALSE do the code as normal :slight_smile:

Thank you for that solution! I just have one more issue and thats when i sprint and aim it cuts it off like you said into the aim. The problem is the camera doesnt set the fov properly during that transition.

Great! Let’s get that figured out, too!

Can you show me your new code? Just the Action: Aim code now! :slight_smile:

No problem!

Try putting print strings in between to see what’s firing and what’s not, I’m not seeing any reason it shouldn’t set the FOV to 70 on the top line regardless of everything else.

Also after the “Is Sprinting” branch, if it’s true, you may want to set “Is Sprinting” to false.

Ok ill try that out after work and the fov works what the camera is doing is changing position like im crouching thats the problem.

Ok then what you need to do is use a custom event, then call that.

Go down to your sprint code, and rclick to “Add Custom Event…”. I’d name it EndSprint because that’s what we’re going to do.

image

And hook it into your sprint code
image

Now go up to your Aim code. Take this node out:

image

And to get your replacement for that, right click and type “End Sprint”. Put this in place of the node you just deleted.

image

So now, it will go down and end the sprint before executing the rest of the code.

Unless I’m misunderstanding and this crouch camera thing isn’t new, but an old problem, this is all I could think to do (better efficiency as well).

Hey thank you so much for everything I can’t wait to get out of work so I can try it! When I do I’ll post an update!

So I found something interesting and I think It’s the real problem. Without any movment input when I click left shift and aim at the same time it shifts the camera up and down.

That is strange, indeed. I’ve never had that happen. It has to be something to do with your code, somewhere. Check your inputs in Project Settings for that, and check the rest of your code. Did you try to put a crouch in at any point and just not remember? That’s all I can think of.

I found the solution in viewport under player camera details I unchecked Lock to Hmd and that made it work. Not sure what Lock to Hmd is haha but hey just want to say thanks for all the help!

Whoa, how weird! HMD is Head-Mounted Display, for reference, so it was talking about a VR/AR headset. Must be commands for testing that are implemented into the FPS Template. Good find! And you’re absolutely welcome!