Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Player movement (Goes through things)

Discussion in 'Scripting' started by Luke3671, Dec 13, 2018.

  1. Luke3671

    Luke3671

    Joined:
    Jul 6, 2014
    Posts:
    52
    FIXED

    Learning Unity and its char movement system with the animator.
    I have this atm but when playing my animator & char is working/moving how it should be work but my whole char goes through things even with rigidbody active.
    is there something i'm missing?
    code is below.

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3.  
    4. public class AJControls : MonoBehaviour
    5. {
    6.     static Animator anim;
    7.     public float speed = 10.0F;
    8.     public float rotationSpeed = 100.0f;
    9.  
    10.     // Start is called before the first frame update
    11.     void Start()
    12.     {
    13.         anim = GetComponent<Animator>();
    14.     }
    15.  
    16.     // Update is called once per frame
    17.     void Update()
    18.     {
    19.  
    20.         float translation = Input.GetAxis("Vertical") * speed;
    21.         float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
    22.         translation *= Time.deltaTime;
    23.         rotation *= Time.deltaTime;
    24.         transform.Translate(0, 0, translation);
    25.         transform.Rotate(0, rotation, 0);
    26.  
    27.         if (Input.GetButtonDown("Jump"))
    28.         {
    29.             anim.SetTrigger("isJumping");
    30.         }
    31.  
    32.         if (translation != 0)
    33.         {
    34.             anim.SetBool("isRunning", true);
    35.         }
    36.         else
    37.         {
    38.             anim.SetBool("isRunning", false);
    39.         }
    40.  
    41.     }
    42. }
    Thank you
     
    Last edited: Dec 13, 2018
  2. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Unless both objects have a collider and a rigidbody component that is NOT set to "IsKinematic"(unless it is the stationary object) it won't expirence any type of physics.
     
    Luke3671 likes this.
  3. Luke3671

    Luke3671

    Joined:
    Jul 6, 2014
    Posts:
    52
    Thank you that fixed it.