Unity 101: 5 ways to move Unity3D Objects

Sdílet
Vložit
  • čas přidán 8. 09. 2024
  • Check out the Course: bit.ly/2S5vG8u
    -------
    Discover 5 different ways to move your Unity3D gameobjects, see some of the differences between them, and learn which one I usually use.
    More Info: unity3d.college

Komentáře • 165

  • @tahirciger8344
    @tahirciger8344 Před 4 lety +109

    00:50 Transform SetPosition
    01:21 Transform Translate
    02:10 Rigidbody AddForce
    03:46 Rigidbody MovePosition
    04:43 Rigidbody SetVelocity

  • @reactor230
    @reactor230 Před rokem +2

    As old as it is I think that this is one of the best tutorials that I have seen about this ever, great job.

  • @bunggo9914
    @bunggo9914 Před 5 lety +19

    so, use transform position if you don't use rigidbody, use rigidbody velocity if you use rigidbody, and use addforce if you want realistic push on an object. moveposition is rarely used, and transform translate works the same as transform position, but you can set the direction relatives.

    • @Aethenthebored
      @Aethenthebored Před rokem

      I know this is a 4 year old comment, but I would disagree. You can have a rigidbody and still want to use transform position change in many cases, like a character mover. I would say ONLY use rigidbody velocity or addforce if you want realistic physics movement for things like bullets

  • @michaelcowley372
    @michaelcowley372 Před 6 lety +18

    I am new to Unity and I was wondering the differences between these methods myself. Thanks so much! I love the content you are putting out!

  • @rapizer3427
    @rapizer3427 Před 6 lety +127

    You should have a fixed update if you are handling rigidbodies

    • @twoshotted
      @twoshotted Před 6 lety +5

      does fixed update make it so that you dont have to use time.deltaTime? or do you still?

    • @mrspazzout1
      @mrspazzout1 Před 5 lety +8

      When moving objects you should always use time.deltatime. It makes the movement more reliable because fixedupdate will fire more times per second on a faster computer compared to a slower one (as far as i understand). time.deltatime simply keeps track of the time between frames so you can rectify this difference.

    • @CodingWithUnity
      @CodingWithUnity Před 5 lety +38

      Any physics movement should be done inside of fixed update.
      Unity's internal physics system runs on the fixed update loop, so if you call changes to it inside of update it will get out of sync and eventually your collides wont be interacting correctly. Take a look at the provided image for a more detailed understanding of how this works
      docs.unity3d.com/uploads/Main/monobehaviour_flowchart.svg
      This should be one of the first things people learn when working with a new engine..

    • @megasoniczxx
      @megasoniczxx Před 5 lety +2

      So, with fixed update does it prevent the values from getting jacked up and causing my object to move more than it was programmed to? To be more specific, when I start my game and, say, jump for example, my object will sky rocket into the air much higher than it normally does when jumping normally. Right now i'm using add force for my jump commands and while this issue could probably be rectified by giving the system time to load, I don't want it to do this ever if I decide to make it available to the public.

    • @megasoniczxx
      @megasoniczxx Před 5 lety +3

      As an update to this I can indeed confirm that having fixed update fixed the issue.

  • @intimidate2161
    @intimidate2161 Před 3 lety +1

    This helped me out on a project I'm working on. Add Force with a rigidbody allows me to adjust the mass of a door so it looks realistic when it open and closes. Thanks for the video!

  • @kubilayg3200
    @kubilayg3200 Před 3 lety +1

    I love rick and morty man! great work! I had no idea you also did unity tutorials, also great.

  • @Gryflir
    @Gryflir Před 5 lety +3

    Hey, I just wanted to provide a small correction since I and other comments seem to be confused about it:
    At 3:05 you were right not to have time.deltaTime. AddForce specifically requires a parameter in Newton (in default mode ForceMode.Force). The physic system handles the timestep component.
    To prove it you can just spawn a cube in a new scene with a rigidBody on it and default parameters (gravity on).
    Then add a script to it with AddForce(mass * acceleration) in FixedUpdate(), where mass is the mass of the rigidBody and acceleration is the gravity but upward (9.81f * Vector3.up by default).
    The result in playmode is that the cube doesn't move.
    Since gravity is applied every physic cycle it means AddForce is compensating for it every cycle too behind the scene else the cube would move.
    note that you can't do that in Update() even if you were trying to "hack" it by multiplying by Time.deltaTime/Time.fixedDeltaTime because the cube would have moved before having its momentum being canceled by the next FixedUpdate.

    • @klauskinnunen7404
      @klauskinnunen7404 Před 3 lety

      Im almos sure that you cant
      Multiply by deltatime anywhere wich includes accerlation some way, because it just doesbt give right answers, thats not only physics based problem, its also if you try make something on your own.
      There is formulas for accerlation calculating using deltatime, but it isnt as simble as multiplying by delta time. If movement is not accerlating then you can multiply by delta time, if its accerlating you cant. You need to use special formula to that

    • @klauskinnunen7404
      @klauskinnunen7404 Před 3 lety

      Fixed update on other hand works perfectly

  • @DavidPatMathis81
    @DavidPatMathis81 Před 3 lety

    BTW, I know this video is older than a lot of tutorials out there, but just wanted to know I really appreciate it and have turned to it many times.

  • @CraftyMaelyss
    @CraftyMaelyss Před 4 lety +1

    Thank you so much, you have no idea how much I've been looking for something like this, since I can't find it in Unity's manuals,
    this is such a huge help!
    I forgot to add, my problem with my current script, is it rotates along the world's axis, so if my player turns around, the controls are inverted.

  • @WoodyGamesUK
    @WoodyGamesUK Před 4 lety

    RigidBody.MovePosition works well with a RigidBody (doesn't have to be kinematic) in case you want to set a new position. The reason is that is uses the physics and actually does the same as setting the velocity with just the right amount to end up on the desired positon. So the physics can be properly resolved in case of collision, which is not the case with setting the transform position directly. This is the reason why in the example you can see the balls with Transform.SetPosition and Transform.Translate (which both set a new position ignoring the physics), both shake when they hit the wall: they are essentially teleporting to a new position and the physics cannot handle it (although the physics can still push the object outside of the wall if it doesn't overlap too much). The other methods (including RigidBody.MovePosition) use the physics and handle the collisions properly.

  • @saadanees7989
    @saadanees7989 Před 5 lety +4

    Thanks man. rb.Velocity saved my day today.

  • @barnesnplebian6462
    @barnesnplebian6462 Před 3 lety

    Yo, I've been looking for a video like this for a week. Thank you!!

  • @funkynormalcat988
    @funkynormalcat988 Před 9 měsíci

    you saved my sanity, thank you so much

  • @DitzelGames
    @DitzelGames Před 6 lety +17

    The velocity/force should not depend on Time.deltaTime. Physics manipulation should be done in FixedUpdate. But besides that. Interesting video!

    • @gizel4376
      @gizel4376 Před 2 lety

      why that? i heard this a lot, but the only argument i've heard was that at high speed you can pass trough wall in update method, but i test it and if my normal speed is 6, i had to set it to 8 000 to pass trough a wall, i use CharacterController.Move, maybe that's related?

  • @DavidBenjaminfirst
    @DavidBenjaminfirst Před 6 lety +1

    Dude! Dude! Thank you! Thank you for this informative, comprehensive & extremely beneficial tutorial. Where I have you been!

  • @bonfaceosuka
    @bonfaceosuka Před 3 lety +1

    Thank you so much for this video , it has really helped me in my project

  • @Renegen1
    @Renegen1 Před rokem

    great visual presentation

  • @dallya7494
    @dallya7494 Před 3 lety

    Thank you so much for making this I was so confused 😅

  • @knightmarerip711
    @knightmarerip711 Před 6 lety

    Excellent work here! Thanx for taking the time to put this together and sharing it!

  • @kharekelas4259
    @kharekelas4259 Před 4 lety

    If you have a lot of colliders under a rigid body, then using rigidbody.MovePosition will save a lot of performance than changing position through transform.

  • @thehustler2825
    @thehustler2825 Před 5 lety +2

    Thanks Jason Thanks a lot Buddy. Love from India.

  • @MrStevebale
    @MrStevebale Před 4 lety

    This is exactly what this newbie was looking for.

  • @florentinlurota3367
    @florentinlurota3367 Před 6 lety +1

    Very clean tutorial, thank you !

  • @RaidenHeaven
    @RaidenHeaven Před 4 lety +1

    The reason the Transform is wiggling is because on every frame it pushes it self inside the collider, and every Fixed Update the Rigidbody pushes the object out.
    Jason should really test Character Controllers here. Rigidbodies update on a fixed timer and if you want high frame rates are not a good option.

  • @Tutterzoid
    @Tutterzoid Před 5 lety

    Awesomeness :) Learnt so much in this short crash course video :) Thanks Jason for sharing this info :)

  • @themaskyyt
    @themaskyyt Před 4 lety

    Thanks man! I finally understand the velocity one

  • @dallyxtenchi2115
    @dallyxtenchi2115 Před 3 lety

    Great tutorial you are a really good teacher 👍

  • @denisgoodman4492
    @denisgoodman4492 Před 2 lety

    The most interesting question is how you move a object with "static collider" in 3D environment (which use the Physic engine). Exist two popular variants - make this object w/o Rigidbody and use Transform or attach to object the Kinematic RB and use the Rigidbody.MovePosition?

  • @krishpaddle1953
    @krishpaddle1953 Před 2 lety

    thanks no other tutorial showed set velocity so thanks.

  • @KanadaVCK
    @KanadaVCK Před 4 lety

    thank you for being there for us 👍👌✌️

  • @mitchiarikov2614
    @mitchiarikov2614 Před 3 lety

    Great video, thank you, Jason!

  • @159donat
    @159donat Před 5 lety +1

    on my top down shooter I used transform SetPosition but the movement looked laggy, then I switched to AddForce which made my movement much smoother and when I go from moving north to west it doesn't just snap move but makes a smooth transition

  • @osamansr5281
    @osamansr5281 Před 6 lety

    awesome video
    I was gonna make the same scene to test them but u saved me some time THANKS

  • @AlexanderZotov
    @AlexanderZotov Před 6 lety +6

    Great tutorial!

  • @kimeiga
    @kimeiga Před 6 lety +1

    thanks for clearing this up!

  • @LetScope
    @LetScope Před 3 lety

    Thanks, great info

  • @cloverross4080
    @cloverross4080 Před 3 lety

    Useful, thank you!

  • @1jerrycamacho497
    @1jerrycamacho497 Před 5 lety

    I'm sorry I'm sorry I'm soooo sorry but... has anyone ever told you that you look like Dan Harmon in your videos? Dude you get me every time....

  • @semiuclips600
    @semiuclips600 Před 4 lety

    transform.Translate worked for me! Thanks a bunch!!

  • @ThoughtShare
    @ThoughtShare Před 3 lety

    Awesome differetiated!!

  • @DamianFloresRF
    @DamianFloresRF Před 5 lety +1

    Did anyone notice why in the last simulation, the one with gravity, the third ball remains coming and going? I think the physics behind that is beautiful.

  • @LuckyLuke980
    @LuckyLuke980 Před 6 lety

    Oh man TNX big time for this tutorial!

  • @dailydoseofchocolate9411
    @dailydoseofchocolate9411 Před 5 lety +5

    hi, great stuff but you forgot to mention Vector3.MoveTowards?

    • @xavmanisdabestest
      @xavmanisdabestest Před 3 lety

      that would be the same as transform.position as you would use vector3.MoveTowards as an input to that function. Hope that helps

  • @sravanstg234
    @sravanstg234 Před 3 lety

    Thank You! This is so helpful

  • @SebSha0
    @SebSha0 Před 4 lety +1

    Thank you so much! I was searching since a while to find the rigid body move script! You did an error in your script but it's simple to correct. Thank you

  • @TonyDaExpert
    @TonyDaExpert Před 4 lety

    This is really useful!

  • @clementsiow176
    @clementsiow176 Před 4 lety +1

    guys why is there a error saying transform does not contain definition for foward

    • @Kshesho
      @Kshesho Před 4 lety

      What method is giving you that error? It's difficult to debug code that you cannot see.

  • @adamemilpaltorp-schmitt1785

    Didn't know Dan Harmon started doing Unity Tutorials

  • @sayedsayed5689
    @sayedsayed5689 Před 6 lety +2

    very helpful

  • @superniqui10
    @superniqui10 Před 4 lety

    Time.deltaTime on the SetVelocity is wrong, you have to feed it the desired velocity in m/s, using Time.deltaTime*50 makes it so that you have 1m/s only when having an fps of 50, making it framerate dependent, the very thing you are trying to avoid. (having lower framerate would actually make it faster since deltatime would be bigger)

  • @beetdatfin
    @beetdatfin Před 6 lety

    thanks! Helpful video

  • @scooterclinic9631
    @scooterclinic9631 Před 4 lety

    Thank u Jason.

  • @fidel_soto
    @fidel_soto Před 5 lety +1

    So you personally rarely use Rigidbody move position and here I am wondering why. It seems like the best option when using physics.

  • @someoneontheinternet3090

    One of the most confusing things when I started learning Unity was whether or not to use a rigidbody to control my character. Most tutorials used transform.Translate but then you would see others saying "if something moves, unless it's a ghost or something, it is affected by physics and should have a rigidbody. If it doesn't have a rigidbody it shouldn't move!" So many people said to never directly manipulate an objects transform. But you say it's how you primarily do it? Or am I super confised about something. That's possible. That is so possible.

    • @Unity3dCollege
      @Unity3dCollege  Před 2 lety

      Depends a lot on if the object is being used by physics. Lots of things are just background items moving around ir things that aren't interacting with rogidbodies or colliders.
      I made a new movement video btw showing a good free unity character controller for movement

    • @someoneontheinternet3090
      @someoneontheinternet3090 Před 2 lety

      @@Unity3dCollege thanks! I'll have a look.

  • @OZcomingFRoo
    @OZcomingFRoo Před 4 lety

    Not sure in the previous version did not have this but I use Unity 2018.3.13 version and I can move a Kinematic type with velocity too.
    I did do it on a 2D object, so maybe 3D Kinematic objects can't be moved via velocity.

  • @DeanWilson
    @DeanWilson Před 4 lety

    So if I wanted boxes to randomly generate from the bottom of the screen to the top of the screen like bubbles. which one would I use? They would not interact with other objects generated.
    Thanks so much, hope someone can help me.

  • @fuzzy-02
    @fuzzy-02 Před 4 lety

    Thanks a bunch

  • @simpson6700
    @simpson6700 Před 5 lety +1

    do you have a similar video about rotations? there are so many different functions for them and they confuse me a lot.

  • @DanieleFerla
    @DanieleFerla Před 3 lety

    Why use deltaTime with AddForce? Aldo the rigidbody operations should be in the FixedUpdate not in the Update method

  • @JustBitsAndPieces
    @JustBitsAndPieces Před 6 lety

    Great stuff

  • @kolemjdouci3350
    @kolemjdouci3350 Před 4 lety

    awesome, thx

  • @georgedowell7747
    @georgedowell7747 Před rokem

    Sir, is there anyway I can make a Transform translate motion smoother or
    Make another rigidbody that can move forward toward any direction.
    Please help me sir

  • @7scars205
    @7scars205 Před 3 lety

    how do you know which way is forward? I made a spaceship in unity and i want it to move sideways but it moves upward

  • @Algeria826
    @Algeria826 Před 5 lety

    Thanks a lot sir

  • @andremilanimartin3338
    @andremilanimartin3338 Před 4 lety +1

    thanks for the tutorial. one question, that code replacer where you renamed several things at once at around 4:30. how do i activate this?

  • @Ramix09
    @Ramix09 Před 5 lety +3

    I didn't know Dan Harmon does unity tutorials!

  • @onur3759
    @onur3759 Před 5 lety

    best tutorial on youtube.

  • @muhammadsameer883
    @muhammadsameer883 Před 4 lety

    Thanks Brother

  • @rodrigo.cs.machado
    @rodrigo.cs.machado Před 6 lety

    Excellent UP UP

  • @lukenukem8028
    @lukenukem8028 Před 4 lety

    You should explain more since moving by Transform is dangerous in the way that you either send objects through objects or get that stupid bounce effect nobody wants. That's what makes Rigidbody movement preferred.

  • @My_Big_Dragon
    @My_Big_Dragon Před 5 lety

    Would you please make a video about frames and how can we do animation within those frame like many VR drawing tools.

  • @jsarnowski
    @jsarnowski Před 6 lety +2

    Cool video! I have one question tho: How can you use Transform SetPosition and don't get this "bouncing off" effect when hitting a collider?

  • @rezazolgharnein7609
    @rezazolgharnein7609 Před rokem

    CZcams's automatic translation does not work
    I have checked many videos, some of them are active and most of them are disabled and only show the English language and the rest of the languages ​​do not show anything even though they are selected, your videos are also disabled.

  • @airdesign.websolutions

    hey, is it necessary to to the * Time.deltaTime for the rb.velocity method? If I don't do it, and just set a lower speed value, wouldn't I get the same result? I don't see how framerate would mess it up in this case...

  • @Tristannn-
    @Tristannn- Před 4 lety

    Can Anyone tell me how to make it so like if I shoot the player moves in the opposite direction

  • @Djrayli2
    @Djrayli2 Před 6 lety

    Please tell me what is the best way (for good performance on mobile) when move non kinematic objects with rigidbody?

  • @JBug20
    @JBug20 Před 6 lety +2

    how do i make it to where an object moves one direction then goes back using addforce?

    • @foodlover195_
      @foodlover195_ Před 5 lety

      Not really relavent to the video, but to answer your question you would just want to inverse the force when it you want it to move back. You would addforce every update by some variable (i.e forceAmount), then for example after it colliders with something you could set the velocity to 0 and inverse the forceAmount variable so that it would move backwards.

    • @CodingWithUnity
      @CodingWithUnity Před 5 lety

      or add the force on a single frame that is enough to bounce it off what you want to bounce off of, and add a bouncy physics material to your rigidbody

    • @JBug20
      @JBug20 Před 5 lety

      thank you both for your input. I will try both to see which would make the best results

  • @faizanhassan5359
    @faizanhassan5359 Před 6 lety

    I am making a carrom game. I want to hit the striker on pieces through keys? What code should I follow to hit

  • @Jay-bb8kc
    @Jay-bb8kc Před 3 lety

    this helped me so much thank you (+1 Sub😁)

  • @danielcraft15
    @danielcraft15 Před 3 lety

    how do i set the velocity afterwards?(the ForceMult thingy)

  • @anupambhattarai8765
    @anupambhattarai8765 Před 5 lety

    Is there any way to remove the collision problem which occurs while using transform.position. I want to stick with transform.position ? I dont want to use rigidbody.addforce(). Please Check the move function in the script.

  • @L1ghtOn3
    @L1ghtOn3 Před 2 lety

    Hi Jason always watch but never post, having real but probably simple to yourself here goes: I have a UI Icon wind arrow that points in the direction of the wind which I set manually to say the x or -x direction and that force acts on the player and it pushes to that direction, great! BUT the UI Icon, when I try to move forward in the Z direction I can get UI Icon to move right facing the x direction I need or -x whatever, but when moving back the way in the -z direction the UI Icon stays the same direction always pointing the same way in x not going 180 flip; Ive tried if(player.transform.rotation.y == 180) or >0 etc etc and also if(player.transform.forward ) ==1) and ==-1 for what I thought was -z, but no tried many if statements many ways to get the icons to move in the desired direction when Im going in the z and -z direction but does not work, the closest I have is this:
    if (Mathf.Abs(Vector3.Dot(Player.transform.forward, Vector3.forward)) == 1) { WindArrow.transform.Rotate(Vector3.forward, 180); }
    and yey it works...or so I thought as the UI arrow rotates 180 every time I enter the OnTriggerEnter area is which activates the if code and being wrong again as it just keeps on flipping each enter no matter whcih way I face twice in thre z foe example grrr, then I tried this:
    if(Mathf.Abs(Vector3.Dot(Player.transform.forward, Vector3.forward)) ==1 { aligned = true; ; }
    {
    if(aligned) { WindArrowL.SetActive(false); WindArrowR.SetActive(true); }else { WindArrowL.SetActive(true); WindArrowR.SetActive(false);
    }
    but the UI only shows up the else condition on both ways walking? I must be misunderstanding the if(Mathf.Abs(Vector3) code or something else, hopefully you can help I know you are busy or a fellow super geek can help moi lol Thanks guys 3 weeks of struggle a new record yey...or nae lol :D

  • @fran.fernandez
    @fran.fernandez Před 4 lety

    how did do u stop the spheres when they hit the wall?

  • @fouadbrk8826
    @fouadbrk8826 Před 5 lety

    Thank's bro i like it

  • @nandorbacso4625
    @nandorbacso4625 Před 5 lety

    How did u create the texts in the ground?

  • @longjohn7992
    @longjohn7992 Před 3 lety

    help addforce wont work at all

  • @g.bagiryan
    @g.bagiryan Před 4 lety

    Hey guys. Could someone help me? Whats the best way to move something like an elevator? I tried many ways but when my Character controller is standing on a rising platform he starts to shake (i'm guessing the elevator collider hits characters collider like in the video). Some say to parent the player from the elevetor onTriggerEnter but in my case it does nothing. I use standard Character controller for the player with applying vertical velocity for gravity in .Move() method I also use a SpereCast for ground checking, the elevator model only has a generated collider the one you get when importing an fbx model and right now I use Vector3.MoveTowards to move it up and down. Any help would be great thanks in advance.
    Edit: after some experimentation I found that if my vertical velocity (gravity) is equal to 0 when I'm grounded, character just falls through the elevator, but if Y velocity isn't 0 (I have it at 6f) he doesn't fall but the stuttering occurs...

  • @looking_arround
    @looking_arround Před 6 lety +1

    Is this secretly Dan Harmon

  • @actual_random
    @actual_random Před 5 lety

    Anyone know how to move locally with velocity ?

  • @qwertusmonster
    @qwertusmonster Před 3 lety

    EPIC

  • @mcgeufer
    @mcgeufer Před 4 lety

    I have a strange issue right now. I use the set position on a transform like mentioned in the video.
    It's called from another class every second. It should move by one per step. But what happens is that it doubles the old value every time and ads 1 on top.
    So it moves from 1 to 3,7,15,31 and so on. Any idea why that happens? I bet I did some silly mistake but I have no idea what it.

    • @bigboobmasterbaiter69
      @bigboobmasterbaiter69 Před 4 lety

      send code

    • @mcgeufer
      @mcgeufer Před 4 lety

      @@bigboobmasterbaiter69 I fixed it!. I called that function in another class with a coroutine.
      And I called another function that triggered the coroutine again by accident.
      That's why it always doubled up. For every start of the coroutine, it triggered one more time.

  • @finalflash1359
    @finalflash1359 Před 5 lety

    can someone tell me some uses for this i initially thought it can be used to move ai on set path during a cut scene but what are some other uses?

    • @Unity3dCollege
      @Unity3dCollege  Před 5 lety

      moving players, npcs, anything else that needs to move around during the game :)

  • @eruchii7200
    @eruchii7200 Před 6 lety

    Hi, how do you that shortcut to make new variable on 4:20?

    • @Unity3dCollege
      @Unity3dCollege  Před 6 lety

      Crtl-. (period) is what I use to create new variables. F2 is what i see at 4:20 though (rename)

  • @marcosrod4718
    @marcosrod4718 Před 5 lety

    How would I move them back and forth?

    • @legomaster6919
      @legomaster6919 Před 4 lety +1

      this is how
      if (Input.GetKeyDown("w") && Input.GetKeyDown(KeyCode.LeftShift));
      {
      transform.position += transform.forward * Time.deltaTime * 2.5f;
      }
      if (Input.GetKeyDown("w"));
      {
      transform.position += transform.forward * Time.deltaTime;
      }
      if (Input.GetKeyDown("s") && Input.GetKeyDown(KeyCode.LeftShift));
      {
      transform.position -= transform.forward * Time.deltaTime;
      }

  • @m1trappy319
    @m1trappy319 Před 4 lety

    how do you make it so it moves when u press a key like W

  • @xWELEWMKMXDXxs
    @xWELEWMKMXDXxs Před 4 lety

    hello sir, how i can transport only 50 pixels like chess moves t

    • @clamum
      @clamum Před 4 lety

      Probably just using the Transform ways would work there. Sounds like you're not working with physics in that case?

  • @PatchCornAdams723
    @PatchCornAdams723 Před 4 lety

    I am trying to make a coin pusher game, but the coins just sit stationary on top of the moving shelf collider, and don't move with it. Then I tried using a script which adds a fixed joint on collision, but now the coins just freeze in place as soon as they touch the shelf. Can anybody help me?

    • @BerrisGaming
      @BerrisGaming Před 4 lety +1

      try unity forums

    • @PatchCornAdams723
      @PatchCornAdams723 Před 4 lety

      @@BerrisGaming Already did, and already solved my problem. Feels good man. Now onto the next problem, lol

    • @BerrisGaming
      @BerrisGaming Před 4 lety

      @@PatchCornAdams723 Yeah its problem after problem. If you run into something agian. Check gamedev.finiox.com for some tutorials.

    • @PatchCornAdams723
      @PatchCornAdams723 Před 4 lety

      @@BerrisGaming Lucky for me, I actually enjoy problem solving, and man this feels like a great way of learning. I can actually feel myself getting better at this with each problem. Thanks a lot btw, I will check out that forum immediately. Cheers!

  • @heytheremogwai
    @heytheremogwai Před 3 lety

    It's amazing how much of a hard time I'm having with this in my 2D game. I'm trying to use a transform.position to a location of my mouse position that I'm grabbing via mousePosition = Input.mousePosition.
    transform.position += (Vector3)direction * (defaultSpeed * Time.deltaTime);
    This only works a few seconds, and then my character kinda sticks to one position and just speeds up and I can't have him walk another direction... Do I need to clear my mousePosition or something?
    I've even tried it with Lerp such as...
    transform.position = Vector2.Lerp(transform.position, direction, default_speed * Time.deltaTime);
    ...which honestly works the best except the further away I click from my sprite the faster he moves... At least he walks around in circles and where I want him to go..
    Can anyone help me?

    • @gizel4376
      @gizel4376 Před 2 lety

      i'm not sure of how you set the whole function, but the way i would do it would be to set a Vector2 variable = (where the mouse click) and depending on how your code is organized you migth need to use LateUpdate function(will always be called after Update(or technicly before since it's a loop))
      in 3D i use CharacterController.Move, i don't know if there's an equivalent in 2D, if not i would probably try with transform.translate which would probably look like this, sorry for the bad syntaxe:
      public float = 6f;
      Vector2 clickPosition = Vector2.zero;
      Vector2 positionDifference = Vector2.zero;
      Vector2 moveDirection = Vector2.zero
      Update()
      {
      if(input.GetButtonDown("fire1"))
      clickPosition = Input.mousePosition;
      positionDifference = clickPosition - transform.position;
      // i'm missing a part to normalize the value into moveDirection, i would have to test it out to be sure
      transform.Translate(moveDirection * speed * Time.deltaTime);
      }
      don't take those line too seriously i'm just a begginer, but maybe it can give you some inspiration to solve your problem

  • @aghaabbas6845
    @aghaabbas6845 Před 5 lety

    Did he just create a presentation in unity???