- Home /
Sprinting animation
I know i have asked this ALOT but everytime it works i change it up , and this ... will be the last time :)
So anyway basicly i have aim down sights script ( NOT mine ) i got it from the wiki , but if i use it then i cant play any animations OR i havr to wait till the animations are done, then it aims down sights , so when i hold up AND shift i want my sprint to play and then i want my gun to return to its original position im trying to look for a fresh script but until then i will lend you one to modify :)
Animation script :
if(Input.GetKey(KeyCode.W))
animation.Play("walkUMP");
if(Input.GetKey(KeyCode.S))
animation.Play("walkUMP");
if(Input.GetKey(KeyCode.A))
animation.Play("walkUMP");
if(Input.GetKey(KeyCode.D))
animation.Play("walkUMP");
else if(!Input.anyKey)
animation.Play("idleUMP");
Aim down sights script :
var nextPos = -0.1597214;
var nextField = 40.0;
var nextPos2 = -0.2532201;
var dampVelocity = 0.4;
var dampVelocity2 = 0.4;
var dampVelocity3 = 0.4;
function Update () {
var newPos = Mathf.SmoothDamp(gun.transform.localPosition.x, nextPos, dampVelocity, .3);
var newField = Mathf.SmoothDamp(Camera.main.fieldOfView, nextField, dampVelocity2, .3);
var newPos2 = Mathf.SmoothDamp(gun.transform.localPosition.y, nextPos2, dampVelocity3, .3);
gun.transform.localPosition.x = newPos;
gun.transform.localPosition.y = newPos2;
Camera.main.fieldOfView = newField;
if (Input.GetButton("Fire2")) {
nextField = 40.0;
nextPos = -0.2202;
nextPos2 = -0.2410035;
GetComponent("CharacterController").maxForwardSpeed = 3;
GetComponent("MouseLook").sensitivityX = 2;
camera.main.GetComponent("MouseLook").sensitivityX = 2;
camera.main.GetComponent("MouseLook").sensitivityY = 2;
} else {
nextField = 60.0;
nextPos = -0.1597214;
nextPos2 = -0.2532201;
GetComponent("CharacterController").maxForwardSpeed = 6;
GetComponent("MouseLook").sensitivityX = 6;
camera.main.GetComponent("MouseLook").sensitivityX = 6;
camera.main.GetComponent("MouseLook").sensitivityY = 6;
}
}
Of course any help will be apprecitated no matter how small the info is :) Thank you for your time
Dont really understand enough about the overall player setup to understand how this would conflict with animations.
For a shot in the dark: make it function LateUpdate so it will overide the animations.
-explain how you made the player -try replacing where it says "Update" with "LateUpdate"
ok i did that , nothing really happening , it just moves a bit further ... the player is just the basic FPS controller and i have my gun attached to my main camera - also attached to my fps controller
Answer by RetepTrun · Dec 15, 2013 at 06:13 PM
No idea what is wrong with the scripts.
You could try a workaround.
in blender or some other program make armature/skeleton with 3 disconected bones. named: Master, cam, gun.
make some sort of mesh to attach to it just so you can adjust the object scale in unity when you import.
create animations. look_down_sight, unlook_down_sight, reload(optional)
import to unity
adjust scale
make the skeleton child of the thing that walks around
re-arrange hierarchy of character. camera should be child of cam bone, master should have the mouse look script that the camera had. The skeleton should be looking around and therefore the camera looking around because it is a child.
skeleton option "always animate" on
animations mode "clamp". (or maybe it was clampforever I cant remember)
now just play the animations when you want them to happen.
Your answer
Follow this Question
Related Questions
Play animation if 2 buttons are held down? 1 Answer
Animations interupting Aim-Script 0 Answers
Cannot get sprint animation to play when crouch works fine? 0 Answers
Aim 360 degrees in 2D game 0 Answers
what's wrong with this script? 2 Answers