Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

player moving without inputs

Discussion in 'Physics' started by crepze21, Aug 15, 2020.

  1. crepze21

    crepze21

    Joined:
    Aug 15, 2020
    Posts:
    2
    i made a script for player movement and my player is moving without any input, is it because its a capsule?
    but at the start when i made the cript it worked fine
     
    Last edited: Aug 15, 2020
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,890
    Could be:
    • Your code is making it move
    • Gravity is making it move
    • Some other script is making it move
    • Collisions with some other object are causing physics forces to make it move
     
  3. crepze21

    crepze21

    Joined:
    Aug 15, 2020
    Posts:
    2
    The last one was it. I removed some walls and now everything is working corectly. Thank you
     
  4. yugiohdeveloper

    yugiohdeveloper

    Joined:
    Aug 19, 2019
    Posts:
    9
    Is there any way that I can prevent collisions with some other objects to force my player to move? I want them to interact to each other but I don't want my player's velocity to be affected from collision.
     
  5. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,890
    You can use trigger colliders. Set the "isTrigger" to true on the collider. Then you can use OnTriggerEnter/Exit to make them interact in script but they won't physically push each other.
     
  6. yugiohdeveloper

    yugiohdeveloper

    Joined:
    Aug 19, 2019
    Posts:
    9
    I don't want the collider to move through another collider. Just wondering whether there is a way to prevent getting some velocity and having two colliders colliding at the same time. For now I'm doing it by assigning Vector2.zero in every FixedUpdate. I just thought there should be a way to close adding force on the UnityEditor
     
  7. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,890
    Enable "kinematic" on the one that you don't want to move.
     
  8. yugiohdeveloper

    yugiohdeveloper

    Joined:
    Aug 19, 2019
    Posts:
    9
    Then I have to do my own gravity system right? Thanks for the reply btw
     
  9. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,890
    Yes, if you make the object kinematic you will have to manually move it. A kinematic Rigidbody cannot be affected by any forces, torques, collisions, or joints. It can only be moved by your scripts.

    You can also leave the body as non-kinematic but limit movement or rotation on any x/y/z axis using constraints on the Rigibody
    upload_2020-8-17_13-13-39.png
     
    yugiohdeveloper likes this.