- Home /
Weapon Possition Move On Sprint
Hi Guys!!! Haven't been on Answers for a while since my computer pooped itself lmao... I'm trying to figure out to create a script for run position... like... if i press the shift key and i start sprinting i want my weapon to drop.. like these pics.
Normal: http://imageshack.us/photo/my-images/809/normala.png/
How i want it to be when i sprint: http://imageshack.us/photo/my-images/41/sprintr.png/
any info will be appreciated on this matter. thank you :)
Answer by DESTRUKTORR · Aug 17, 2012 at 03:00 AM
There's a number of ways to do this, as with many simpler mechanics/systems people usually ask for help with on here (not that there's anything wrong with that just... be prepared for a slew of options :P).
Use an animation. Simple as that. Make the animation, and make it play when you sprint.
Manually rotate the gun, over time. Quaternion.slerp is pretty good for this. You may also need Vector3.Lerp.
Rotating/transforming with Time.deltaTime (the amount of time between the last frame update and this one) multiplied by some number is another way to manage doing something "over time," so I would suggest using it alongside a rotation/translation call.
Off the top of my head, those three would be the most practical. If you've got any specific questions on them, check the documentation links, or drop a comment, and I'll try to answer them.
Okay... i looked at Quaternion.slerp and this seems good... but the basic function is
var from : Transform; var to : Transform; var speed = 0.1; function Update () { transform.rotation = Quaternion.Slerp (from.rotation, to.rotation, Time.time * speed); }
How would i create a if statement for it only to happen if i press the "Sprint" Button...
var gunTrasnform : Transform;
var sprintRotation : Quaternion;
var normRotation;
var rotationRate : float;
var isSprintRotated = false;
function Start()
{
normRotation = transform.localRotation;
}
function Update()
{
if(Input.GetButton("sprint"))
{
gunTrasnform.localRotation = Quaternion.Slerp(gunTrasnform.localRotation, sprintRotation,Time.deltaTime*rotationRate);
if(gunTransform.localRotation==sprintRotation)
{
isSprintRotated=true;
}
}
else if(!Input.GetButton("sprint")&&isSprintRotated)
{
Quaternion.Slerp(gunTrasnform.localRotation, normRotation, Time.deltaTime*rotationRate);
}
}
I think this should work... forgive me if there's some syntax errors... I'm a C# programmer, but I know enough Java Script to translate, for the most part.
Also, be sure you enter the "sprint" key in the Input menu, in the editor. You can find it under Edit>Project Settings>Input
There was few errors but i fixed those... Thanks for this :)