- Home /
Sprint position for gun
Hi, I have a working sprint script that works very well, but I want even better performance by making my guns going into a sprinting position when the shift key is held down. Does anyone know how to to this, because I think it has something with quaternions to do with, but I don't know anything about quaternions. Anyone?
Yes, I am, because transform.rotation doesn't work for me
Answer by BossGrand · Oct 29, 2013 at 05:05 PM
First you need to find your gun transform. So I'm assuming its in your hierarchy. So this is how you'd grab it.
public void sprint()
{
Tranform gunTransform = transform.Find("Gun").transform;
gunTransform.Rotate( new Vector3(PitchDelta,YawDelta,RollDelta))
//other sprint related stuff
}
pitch/yaw/roll delta are floats of how much you want to rotate. I'd save the current rotation as well so that you can snap it back after you're done sprinting. Also you'll want probably want to use some form of Lerp to make it a smooth movement
I edited my post to explain. But they are just the float values of how much you want to change the rotation.
Your answer
![](https://koobas.hobune.stream/wayback/20220613120856im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Turret on Tank rotating fine until I'm not flat on ground 1 Answer
Set rotation based on 1,1,1 style vector? How to convert vector3 to quaternion? 1 Answer
Root Animations are inaccurate 0 Answers
Why is Quaternion.Eular only rotating in one direction? [Answered] 1 Answer
How to always rotate clockwise 1 Answer