Skip to content

Instantly share code, notes, and snippets.

@jzevin
Created November 29, 2024 12:23
Show Gist options
  • Save jzevin/b8f13608be1cbb23968a984c3b418778 to your computer and use it in GitHub Desktop.
Save jzevin/b8f13608be1cbb23968a984c3b418778 to your computer and use it in GitHub Desktop.
Unity Movement - 4 Ways to Move CheatSheet
  • from: https://www.youtube.com/@sasquatchbgames
  • Transform Translation:
    • Pros
      • You’ll have EXTREMELY precise control over movement, acceleration, collisions, and everything
      • You don’t need a Rigidbody (unless you want to call OnTriggerEnter2D, then you need a kinematic RB and collider)
    • Cons
      • More setup as you have to create your own collision detection
      • Does not work with physics forces (ex. RB.AddForce)
    • Notes:
      • Use in Update
      • Multiply by Time.deltaTime to get consistent speed
  • RB.MovePosition
    • Pros
      • Precise control over movement, acceleration
      • Collisions work right out of the gate
    • Cons
      • Conflicts with physics forces
    • Notes:
      • Use in FixedUpdate
      • Multiply by Time.deltaTime to get consistent speed
      • Set RB to ‘Interpolate’ for smooth movement
  • RB.AddForce
    • Pros
      • Collisions work right out of the gate
      • Works well WITH physics forces
    • Cons
      • Not as precise as other methods. Not good for pixel-perfect platformers for example.
      • More work to get consistent movement that isn’t too floaty up-front
    • Notes:
      • Use in FixedUpdate
      • Does not need to be multiplied by Time.deltaTime.
      • Set RB to ‘Interpolate’ for smooth movement
      • You’ll likely need to set a maxSpeed of some kind, and acceleration/deceleration controls to get your character feeling less slippery.
  • RB.Velocity
    • Pros
      • Extremely easy to setup
      • Collisions work out of the gate
    • Cons
      • Overwrites physics forces (can make movement problems difficult to debug.)
    • Notes
      • Use in Update
      • Does not need to be multiplied by Time.deltaTime.
      • Set RB to ‘Interpolate’ for smooth movement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment