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. Dismiss Notice

Best practice for moving character objects

Discussion in 'Physics' started by dgingi, Aug 7, 2022.

  1. dgingi

    dgingi

    Joined:
    Jan 4, 2021
    Posts:
    6
    Hi guys,

    I'm building a sports game and I have the following settings and reqs:
    • I have idle/walk/run animations for the players
    • The animation doesn't move forward, just animates the movements.
    • I have several attack and defense players at each stage
    • Players should not go through one another
    My question: what is the most correct way to move the players, but still have the collide with each other?

    At first, I was moving the players with transform = Vector3.MoveTowards, but this caused me to miss collisions.
    So I switched on using rigidbody.MovePosition.
    In both options, I use isKinematic=true, when I try to remove this the character itself starts to fall and fly around once I use rigidbody.MovePosition

    Any suggestion on what is the correct way to move them + use the animations + get all collisions?

    Thanks in advance!
     
  2. knobblez

    knobblez

    Joined:
    Nov 26, 2017
    Posts:
    223
    From (https://docs.unity3d.com/ScriptReference/Rigidbody-isKinematic.html): "Kinematic rigidbodies are also particularly useful for making characters which are normally driven by an animation, but on certain events can be quickly turned into a ragdoll by setting isKinematic to false." Might explain why they are going crazy when you turn it off.

    Is gravity checked or unchecked for the rigidbody? Does something happen when two players run into eachother at a certain velocity? Colliders can be gone through if the gameObject is going too fast. I've found that playing with Mass can help a little bit with this.

    I don't know how hard this hits performance but I have fixed missed collision issues before by adjusting Timestep. Project Settings> Time> Fixed Timestep. This adjusts how often Unity performs physics calculations. I believe the value is the time between calculations so the smaller it is, the more calculations.
     
    Last edited: Aug 8, 2022