• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: My script for Sprinting and Crouching doesn’t work;

Resolved: My script for Sprinting and Crouching doesn’t work;

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I am actually trying to make the player Sprint by pressing the LeftShift key and Crouch by pressing the LeftControl Key.
I attached the C# Code at the bottom. So here, the Shift key works, because I tested by using Debug.Log(“Sprint Triggered”) when the key is pressed, and the Crouch key works too in the same way.
But, when I press Shift, the speed of the player doesn’t change at all. And also, when I press crouch, the player just gives a really really quick jump up.
I have set all the variables correctly, I double checked them. But I don’t know why there is no change in the motion of the body.
Let me know if you need any more details

Answer:

The body is changing, just that its only in the moment you press down the key and then it returns to its normal state. You can make a function that checks for holding/releasing certain keys and modifies a bool variable that your sprint/crouch function will read, like this:
Also a note to make your code cleaner you can declare similar variables using a , like so:

If you have better answer, please add a comment about this, thank you!

c# unity3d
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Modify entity using Action in C#

24/03/2023

Resolved: How to give rank on datetime column group by another column with userid in it

24/03/2023

Resolved: Passing 2 functions in onChange in react

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.