4 Ways to MOVE (Pros and Cons) in Unity

Поделиться
HTML-код
  • Опубликовано: 13 июн 2024
  • Show your Support & Get Exclusive Benefits on Patreon (Including Access to this tutorial Source Files + Code) - / sasquatchbgames
    Join our Discord Community! - / discord
    --
    Let's break down and analyze the most popular ways to move your player in unity, and talk about the pros and cons and when you might want to use which.
    --
    Timestamps:
    00:00 - Intro
    00:22 - Transform Translate
    02:42 - rb.MovePosition
    04:17 - rb.AddForce
    06:12 - rb.Velocity
    --
    Links (Free asset pack used in video)
    assetstore.unity.com/packages...
    Ways to move ChEATSHEET:
    docs.google.com/document/d/1M...
    ---
    In need of more Unity Assets? Using our affiliate link is a great way to support us. We get a small cut that helps keep us up and running: assetstore.unity.com/?aid=110...
    ---
    Who We Are-------------------------------------
    If you're new to our channel, we're Brandon & Nikki from Sasquatch B Studios. We sold our house to start our game studio, and work full time on building our business and making our game, Veil of Maia.
    Don't forget to Subscribe for NEW game dev videos every Monday & Thursday!
    Wishlist our games:
    Wishlist Samurado!
    store.steampowered.com/app/23...
    Follow us on Twitter for regular updates!
    / sasquatchbgames
    #unitytutorial #unity2d #unity3d
  • ИгрыИгры

Комментарии • 44

  • @THEBLNKY
    @THEBLNKY 3 месяца назад +6

    Watching the video I thought "This is great - I should put that into a cheat sheet for quick reference"...and then you ended with "Here's a cheat sheet." Thank you! ❤

  • @ZacMarvinGameDev
    @ZacMarvinGameDev 3 месяца назад +6

    This is a really solid video for understanding the difference between the types of movements. And would be a great reference for any Unity developers starting a new project and deciding which route to go. I will be saving this and referring to it at each project as a quick refresher. Good work!

  • @Konitama
    @Konitama 3 месяца назад +4

    For my own top down game I use rigid body with AddForce. It's by far the most flexible just because it plays nicely with the physics system. As you said, you can add knockback or other physics based things directly on top of the player's movement... so things can push the player around while the player can still move.
    For my player controller, I didn't add artificial acceleration/deceleration and just used the Rigidbody2D settings. I created a frictionless material, then set Mass to 150, Linear Drag to 40 and Angular Drag to 0.05. Then when I add enough force to the rigidbody, it will move perfectly. There is no acceleration/deceleration, so when you move around it's 1:1 and feels very responsive. The character moves at full speed immediately and stops instantly, but has all the benefits of physics collisions. The movement is basically Legend of Zelda top down movement but with physics.
    I think what trips most people up is that they don't mess with the Rigidbody 2D settings enough, so they think using AddForce just results in a floaty mess, but you can tweak these settings to be perfect for the movement you're looking to create.

  • @Nicolas-tr3sk
    @Nicolas-tr3sk 2 месяца назад

    Nice video, it really helps understanding movement for beginners. Every other tutorial for moving just chooses a method and doesnt tell you about the other ones

  • @seaderwerks3046
    @seaderwerks3046 3 месяца назад +2

    I wish you posted this a week ago when I was having issues with applying a knockback while my movement handling was in Update. I ended up figuring out on my own that I needed fixedUpdate to get it to work. Just find it funny that I was dealing with this issue that took me hours to figure out for you to only post this video today lmao! Good stuff!

  • @castlecodersltd
    @castlecodersltd 3 месяца назад +1

    This is a great reference video, definitely bookmarking. Thanks 🙂

  • @FrogKin9
    @FrogKin9 3 месяца назад

    Nice to have a video seeing it explained this quick and well. I was always struggling with this topic. It definetly gets into my GameDev Playlist! :) Thanks. Just have to figure out what's different for my 3D games.

  • @newleafgames
    @newleafgames 3 месяца назад +1

    Very informative. Appreciated

  • @gameboardgames
    @gameboardgames 3 месяца назад

    Super-useful video thanks! I'm reworking my object movement today in my solo-indie-dev game, RoadHouse Manager, and this has been so helpful.

  • @beatrageGameSalad
    @beatrageGameSalad 2 месяца назад +1

    This is called BEST PRACTICE!
    Learn this and you're half way to make a good game my friends! 😎👍

  • @asig396
    @asig396 2 месяца назад

    You are the best of the best explaining things. I hope you can upload a tutorial for picking objects in 2D and in 3D not using RayCast, it cost me a lot to understand the power of the trigers.

  • @_jonathancollins
    @_jonathancollins 3 месяца назад +1

    It's nice to see these side by side. I generally knew the basics of each, but the pros and cons are really handy. Thanks!
    Are there any notable differences in these from 2d to 3d?

    • @sealsharp
      @sealsharp 3 месяца назад

      Yes, there are.
      In 3D there is vertical movement like stairs and uneven ground. The unity CharacterController briefly mentioned at 07:28 is made specifically for that purpose.
      In 3D first person, the camera is linked to the character position which means that even a little unevenness in movement looks absolutely horrible. Standing on moving objects like elevators is often done by temporarily parenting the player but physical movement happens in FixedUpdate and so any combination of player character being moved by other objects gets kinda tricky.
      Depending on the artstyle and camera perspective, the syncing of animations and movement requires more work and using root animations, where the animation system drivers the movement, may be required for it to look good.

  • @ReservedLaughter
    @ReservedLaughter 3 месяца назад

    nice video! RB.Velocity ftw!

  • @galassie-dev
    @galassie-dev 3 месяца назад

    Nice video!
    One "problem" is that you are not mentioning anything about linear drag that interacts with forces applied to a rigid body! It could be useful to have an update on this topic! :)

  • @MarushiaDark316
    @MarushiaDark316 3 месяца назад

    One thing that's a bit more advanced that helps with any of these, but especially with the rb.velocity method is using a Finite State Machine to set the velocity based on state changes. So Idle is defined as velocity zero, Jump is defined as velocity.y being positive, Falling as velocity.y being negative, etc. Alternatively, you could use GOAP as well, which is even more advanced.

    • @sasquatchbgames
      @sasquatchbgames  3 месяца назад +1

      very true, i mainly use rb.velocity along with a finite state machine as mentioned. Haven't tried the GOAP yet though

  • @FeyFen
    @FeyFen 3 месяца назад

    great tut!

  • @ferranrojas5899
    @ferranrojas5899 3 месяца назад

    dude you are awesome

  • @Dinkymod
    @Dinkymod 3 месяца назад

    Loved the video! I'd actually be interested in coverage of the Character Controller if you get around to making a 3D version of this vid.

  • @t33h33studio
    @t33h33studio 3 месяца назад

    Personally, I love rb.Velocity. You need to modify your thinking/setup such that it's open to forces being added. Rather than setting the velocity directly through movement, you should have player's intended movement be one part of setting a velocity. With it getting either multiplied. subtracted, or added with to other forces that intended to interact with the Player.

  • @User609-iu5co
    @User609-iu5co 3 месяца назад

    There is also one good method for tilebased games that uses interpolation between discrete tile positions.Its fast, since no physics calculations are needed and positions are always exact.

  • @briantrochim474
    @briantrochim474 2 месяца назад

    i see you have input manager up there on the 4th option, are you using the new input system for just the forth option? or are you using it for all of them? also which of these four are best for combat? such as dashing, dodging, and knockback?

  • @1oglop1
    @1oglop1 3 месяца назад

    Is there a way to emulate canvas-like selection but with a game object? I am trying to emulate the feel of cursor hopping from one item to the other. But it is really fast (fps fast), so I implemented it as a coroutine which delays the next move. I wonder if there's a better way to do it.

  • @Luckypanther
    @Luckypanther 3 месяца назад

    So question I been looking for is why do others use vectors? Instead of using translate( 0, 0, 1) or whatever.

  • @BottleHeadGames
    @BottleHeadGames 3 месяца назад

    What about the velocity one? You didn't tell how to overcome the overriding of it and using add force a long side it... I was once stuck because of this thing couldn't find why or how to resolve it when manipulating the velocity directly.

  • @roarlee6387
    @roarlee6387 3 месяца назад

    Beginner comment here: That InputManager.Movement looks like it should be a vector based on the x and y input. Where is that defined? I don't seem to have that input capture method available to me in my script.

    • @sasquatchbgames
      @sasquatchbgames  3 месяца назад +1

      that's based on a manual input script I created. (You could check out the Top-down movement tutorial, it's exactly the same) - Just a personal preference of mine

  • @sealsharp
    @sealsharp 3 месяца назад

    Using the animators root motion is also a way to control. In modern realistic games with a visible character, that is the primary way to do it because it syncs movement and animations the best.
    One big issue is also the linking between hero and camera. In 2D that is not muhc of an issue as the camera is external and its so easy to tween. 3D first person, holy fuck that is a mess.

  • @gersti_15
    @gersti_15 3 месяца назад

    Is it possible to make a dash with all of this methods?

    • @BailyGameDev
      @BailyGameDev 3 месяца назад

      Yes. rb.AddForce is the easiest to add a dashing mechanic to it, but the others are all very possible. I use rb.Velocity and added an if(dashing == true){dash code}else{move code} in the fixed update.

    • @kingbling7571
      @kingbling7571 3 месяца назад

      Yup, u stop the movement code when dashing and start the movement code when done with dashing

    • @MarushiaDark316
      @MarushiaDark316 3 месяца назад

      To answer the question, we just have to think about what it means to actually dash. When we say dash, we mean a sudden and usually temporary burst of speed. Each of these methods is just a way of applying speed. So you would just use that method to raise the speed and then wait a bit and lower it back down again.

  • @emreberatkr
    @emreberatkr 3 месяца назад

    02:57 You don't have to multiply by neither deltaTime nor fixedDeltaTime. In FixedUpdate their value remain the same every call so its an unnecessary calculation. Both of them always return 0.02f by default.

    • @sealsharp
      @sealsharp 3 месяца назад

      If we are technically pendantic, then no.
      The FixedUpdate does not run at 50FPS default, it runs as often as it is required before the visual frame to ensure that physics happen in small enough steps for the physics algorithms to work. The FixedUpdate-Calls are also not equidistant in their time of appearence.
      If you search the unity forums, you can find people doing statistics and standard deviations of the true frequency and deltas of FixedUpdate-Calls depending on actual Update-FPS.
      Also, the FixedUpdate frequency can be changed, but even changing it to match 60FPS on an 60FPS locked games does not ensure a 1:1 between Update() and FixeUpdate().

    • @emreberatkr
      @emreberatkr 3 месяца назад

      @@sealsharp I didn't say that its runs at 50fps but the value is never changed during the runtime. So the value is constant and unnecessary to multiply with it. You may log the value and see its never change.

    • @gameweavers
      @gameweavers 3 месяца назад

      Official examples include multiplying by Time.fixedDeltaTime,docs.unity.cn/cn/2022.1/ScriptReference/Rigidbody2D.MovePosition.html

  • @MehmetSarkd
    @MehmetSarkd 3 месяца назад

    No charactercontroller ?

    • @sealsharp
      @sealsharp 3 месяца назад

      At 07:28 our hero, the CharacterController get's a mention. In a 3D game, this would be weird to leave out since CharacterController is a solution to so many complications on 3D.

    • @MehmetSarkd
      @MehmetSarkd 3 месяца назад

      @@sealsharp thanks i didn't watch the video cuz i wasn't interested in other methods

  • @Coco-gg5vp
    @Coco-gg5vp 3 месяца назад

    First