Sprinting animation

I know i have asked this ALOT but everytime it works i change it up , and this … will be the last time :slight_smile:

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 :slight_smile:

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 :slight_smile: Thank you for your time

No idea what is wrong with the scripts.

You could try a workaround.

  1. in blender or some other program make armature/skeleton with 3 disconected bones. named: Master, cam, gun.
  2. make some sort of mesh to attach to it just so you can adjust the object scale in unity when you import.
  3. create animations. look_down_sight, unlook_down_sight, reload(optional)
  4. import to unity
  5. adjust scale
  6. make the skeleton child of the thing that walks around
  7. 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.
  8. skeleton option “always animate” on
  9. animations mode “clamp”. (or maybe it was clampforever I cant remember)
  10. now just play the animations when you want them to happen.