Search Unity

No longer adds force

Discussion in 'Scripting' started by DeeJayVee, Jan 24, 2015.

  1. DeeJayVee

    DeeJayVee

    Joined:
    Jan 2, 2015
    Posts:
    121
    *SOLVED; It was my actual animations, I moved the object as a whole, and not the armature.

    Hey guys, I've moved from character joints to making basic blender models with bones, and the animations are alot smoother, however, when I change animations and try to addforce, the character no longer moves,

    is it my script?

    Code (CSharp):
    1. using System.Collections;
    2.  
    3.  
    4.  
    5.  
    6. public class StickMovement : MonoBehaviour {
    7.  
    8.     public float forwardSpeed = 10;
    9.     public float backwardSpeed  = 8;
    10.     public float jumpHeight = 10;
    11.     public float rotateSpeed = 10;
    12.  
    13.     Animator anim;
    14.  
    15.  
    16.     void Start () {
    17.         anim = GetComponent<Animator>();
    18.     }
    19.  
    20.  
    21.     void Update () {
    22.         Movement();
    23.  
    24.     }
    25.  
    26.     void Movement(){
    27.         float hori = Input.GetAxisRaw ("Horizontal");
    28.         float verti = Input.GetAxisRaw ("Vertical");
    29.        anim.SetFloat ("Speed", verti);
    30.  
    31.         //Directional Movement
    32.         if(hori < 0)
    33.         {
    34.             rigidbody.AddForce(-forwardSpeed, 0, 0);
    35.         }
    36.      
    37.         if(hori > 0)
    38.         {
    39.             rigidbody.AddForce(forwardSpeed, 0, 0);
    40.         }
    41.  
    42.         if(verti < 0)
    43.            {
    44.             rigidbody.AddForce (0, 0, -forwardSpeed);
    45.         }
    46.  
    47.         if(verti > 0)
    48.            {
    49.             rigidbody.AddForce (0, 0, forwardSpeed);
    50.         }
    51.    
    52.         //  Crouching
    53.         if(Input.GetKey ("x"))
    54.            {
    55.             anim.SetBool ("Crouch", true);
    56.         }
    57. else {
    58. anim.SetBool("Crouch", false);
    59. }
    60.     }
    61. }
     
    Last edited: Jan 25, 2015
  2. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    899
    Does you animator have "Apply Root Motion" set?
     
  3. DeeJayVee

    DeeJayVee

    Joined:
    Jan 2, 2015
    Posts:
    121
    Oh yes, thank you for trying to help me PGJ, I realized my problem, when I made the crouching motion, I moved the object down as a whole, and not just the armature, so, when I remade my animations, I found that mistake with testing, and I rectified it, I had forgotten about this post.

    Again, thank you.