Rotating in the Direction of Movement 2D (Unity Tutorial)

  Рет қаралды 59,525

Ketra Games

Ketra Games

Күн бұрын

Пікірлер: 108
@Not__Steven
@Not__Steven 2 жыл бұрын
The clarity in both what you're doing and how is actually AMAZING, thank you so much
@KetraGames
@KetraGames 2 жыл бұрын
Thanks very much for this comment 😊
@IroquoisPliskin86
@IroquoisPliskin86 3 жыл бұрын
Fantastic tutorial. Just a pleasant sounding voice explaining exactly what you need to do with no filler, no mistakes that you get a lot when people film them live, just the tutorial and the code and what it does. This is how every Unity tutorial should be. Well done.
@KetraGames
@KetraGames 3 жыл бұрын
Love this comment! Thank you 😊
@user-ez7ls2du9c
@user-ez7ls2du9c 2 жыл бұрын
Thats great now do it with a rigidbody. transform.Translate does nothing with physics, so this code "works" but its useless 99% of the time unfortunately
@jahoopyjaheepu497
@jahoopyjaheepu497 2 жыл бұрын
@@user-ez7ls2du9c I'm using this code in a very similar way with a kinematic rigidbody. It is not useless; you just don't understand how to use rigidbodies and transform together.
@akhilkrishna5282
@akhilkrishna5282 3 жыл бұрын
Thank u soo much, i searched a lot in google and youtube and u were the only one to have a good video about the rotation........hope ur channel grows lot as people like u really deserve it......lots of thanks
@KetraGames
@KetraGames 3 жыл бұрын
Thanks so much for this! That's great to hear 😊
@casuallyaddicting6452
@casuallyaddicting6452 3 жыл бұрын
Thank you so much for the 2d rotation! Hope your channel grows fast.
@KetraGames
@KetraGames 3 жыл бұрын
Thanks 😊
@TheOnlyOwnedbyCow
@TheOnlyOwnedbyCow 3 жыл бұрын
Thank you! I've went through a ton of tutorials trying to find someone that actually uses Unity 2d the way that it is set up. You are the only person that I have found that use X and Y for movement and X for rotation. It took me about 6 hours to find your video. You had the exact solution that I was needing. Good job! Subbed.
@KetraGames
@KetraGames 3 жыл бұрын
Thanks for this. Glad it was helpful 😊
@DarkHunterThany
@DarkHunterThany Жыл бұрын
Thank you!! I was stuck on this for hours then had it fixed in minutes thanks to your video.
@franchisethebull
@franchisethebull 2 жыл бұрын
Hey, very concise and useful tutorial, was able to adapt it to what I needed for my code very quickly. Thank you champ
@KetraGames
@KetraGames 2 жыл бұрын
Thanks for this comment, good to hear 😊
@volkerherfeld3225
@volkerherfeld3225 3 жыл бұрын
Thanks a lot! This is a great tutorial that fixes a problem I've been having with a top-down tank game!
@KetraGames
@KetraGames 3 жыл бұрын
Glad you found it useful 😊
@goodgamershow6505
@goodgamershow6505 3 жыл бұрын
Thank you very much for your tutorial, it helped me really well. I thought programming rotation would be much harder, but you solved my problem with just 2 lines of code, lol. UPD: If anybody faces a problem with player not rotating, make sure your "Rotation Speed" variable is assigned and have a really big value. For me value of 3500 was just great, because in my game player needs fast rotation.
@KetraGames
@KetraGames 3 жыл бұрын
Glad to hear this, thanks for your comment 😊
@vincn9760
@vincn9760 2 жыл бұрын
i was struggling to do this for so long. no finally I got it working. Thank you so much
@KetraGames
@KetraGames 2 жыл бұрын
Great to hear, thanks 😊
@iml-ilustresmemeslegendado3554
@iml-ilustresmemeslegendado3554 3 жыл бұрын
Thank you VERY much. Exactly what i was looking for. I was crazy searching about it. God bless you and your channel
@KetraGames
@KetraGames 3 жыл бұрын
Great to hear this. Thanks very much for your comment 😊
@mathiasaxelsson7842
@mathiasaxelsson7842 2 жыл бұрын
Thank you for this! This was the exact kind of rotation for my enemy I wanted to achieve. However in my case I needed the an enemy rotate towards the player without snapping directly to the player direction.
@KetraGames
@KetraGames 2 жыл бұрын
Great to hear, thanks 😊
@andrewfedorov9198
@andrewfedorov9198 2 жыл бұрын
Such a good and clean tutorial. Thank you!
@KetraGames
@KetraGames 2 жыл бұрын
Thanks for this comment 😊
@frederick7795
@frederick7795 3 жыл бұрын
Perfect, exactly what I'm looking for
@KetraGames
@KetraGames 3 жыл бұрын
Glad you found it useful 😊
@Myzzz12
@Myzzz12 2 жыл бұрын
This is exactly what I needed, thanks!
@KetraGames
@KetraGames 2 жыл бұрын
Great to hear 😊
@sonesaile
@sonesaile 2 жыл бұрын
Exactly what I needed. Thank you. Great tutorial.
@KetraGames
@KetraGames 2 жыл бұрын
Glad it was useful 😊
@RainZzxHDx
@RainZzxHDx Жыл бұрын
Easy and Quick to understand. Thanks for the good Tutorial 😁
@KetraGames
@KetraGames Жыл бұрын
Great to hear, thanks 😊
@se5d
@se5d Жыл бұрын
thank you. exactly what i was looking for
@KetraGames
@KetraGames Жыл бұрын
Great to hear 😊
@hahumbra
@hahumbra Жыл бұрын
Excellent explanation. Thanks
@KetraGames
@KetraGames Жыл бұрын
Great to hear 😊
@rgodoy86
@rgodoy86 Жыл бұрын
Lifesaver, many thanks!
@umgefallenesglas8213
@umgefallenesglas8213 3 жыл бұрын
THANK YOU THAT WAS WHAT I NEEDED
@KetraGames
@KetraGames 3 жыл бұрын
Great, glad it was useful 😊
@DARÉ_REBELO
@DARÉ_REBELO 3 жыл бұрын
thanks very much. exactly what I was looking for.
@wanderingturtle1705
@wanderingturtle1705 2 жыл бұрын
Amazing work as always.
@KetraGames
@KetraGames 2 жыл бұрын
Thank you! 😊
@ZeroChronicles01
@ZeroChronicles01 3 жыл бұрын
Omg this is what I've been wanting thank you! I'm also curious about this but in the new input settings for unity? Can this still work?
@KetraGames
@KetraGames 3 жыл бұрын
Hi, yes you can make this work with the new input system. The rotation part would be the same. You would just need to replace the section where the input is retrieved with the new input system.
@animeeditor5108
@animeeditor5108 7 ай бұрын
Amazing it help me to make a game! Keep going!
@KetraGames
@KetraGames 6 ай бұрын
Great to hear, thanks 😊
@megasoniczxx
@megasoniczxx 10 ай бұрын
Not sure if you still see the comments for these videos but I wanted to ask if you know how to get it so that when you turn the exact opposite direction (say my character is facing forward and I go immediately back) how would you make it so that the player doesn't slightly shift to the side when this happens? To further illustrate, if I were to keep moving up and down without pressing either right or left my character would be constantly going further along the X axis the more I do this and i'm not sure of the method to prevent this outside of possibly boosting the rotation speed to obscene levels.
@decalibrator3434
@decalibrator3434 2 жыл бұрын
I love you, thank you for doing these videos!
@KetraGames
@KetraGames 2 жыл бұрын
Thanks for this comment 😊
@Moon-cr4mu
@Moon-cr4mu 2 жыл бұрын
very helpful tutorial
@KetraGames
@KetraGames 2 жыл бұрын
Great to hear 😊
@kennethbailey9802
@kennethbailey9802 3 жыл бұрын
you sound a little bit like Adon from Turok 2, thanks for the tutorial!!
@KetraGames
@KetraGames 3 жыл бұрын
😂 Glad it was useful
@revana9448
@revana9448 3 жыл бұрын
Thank you so much!
@KetraGames
@KetraGames 3 жыл бұрын
👍😊
@danielmerki6644
@danielmerki6644 2 жыл бұрын
Thank you for this helpful instruction and the working script template. Can you maybe help me? I need this function for an enemy that automatically moves to different waypoints. The waypoints are located in a grid. The enemy can drive up, left, right and down. Every time he turns he should change the direction. I am still a beginner and would like to learn it and would be very grateful for your help.
@KetraGames
@KetraGames 2 жыл бұрын
Hi, you can work out the waypoint from the enemy by subtracting the enemy position from the waypoint position. Then you should be able to use this direction to do the rotation as shown in the video. Hope that helps 😊
@nsr43d
@nsr43d 2 жыл бұрын
Great Tutorial thank you very much, it`s really helped me.
@KetraGames
@KetraGames 2 жыл бұрын
Glad it was useful 😊
@kunz4164
@kunz4164 3 жыл бұрын
Glad I discovered this channel. Can you do some 2D related tutorials like Visual novel stuff, or like a map feature where you can click on a place on the map and you can see the player icon move to that location using closest path and then transition to that map?
@KetraGames
@KetraGames 3 жыл бұрын
Thanks. We'll definitely look to branch out into more 2D tutorials in the future 😊
@felipemeridareinaga
@felipemeridareinaga 3 ай бұрын
amazing video thanks
@KetraGames
@KetraGames 3 ай бұрын
Thanks for this comment 😊
@abdellatifqassid4687
@abdellatifqassid4687 Жыл бұрын
Thank you so much
@leomenz9
@leomenz9 3 жыл бұрын
thank you so much!!!
@KetraGames
@KetraGames 3 жыл бұрын
👍😊
@fluturehundozi510
@fluturehundozi510 2 жыл бұрын
Thank you very much for this tutorial! I was wondering, is there a way to make the object move as soon as the game starts and make it move constantly? I can't seem to figure out that one.
@KetraGames
@KetraGames 2 жыл бұрын
Hi, I think rather than having the movement driven by the player input you would want to move it at a constant speed in the Update method. Hope that helps 😊
@attrick4433
@attrick4433 Жыл бұрын
How would i connect this to a ai pathfinding script that follows the player? I'm new to programming and I'm using the 'Astar pathfinding' scripts.
@KetraGames
@KetraGames Жыл бұрын
Hi, this video may help - kzbin.info/www/bejne/jnnViKeCj9mtr5o
@wanderingturtle1705
@wanderingturtle1705 2 жыл бұрын
This might be a silly question but what makes Vector3 necessary for the Quaternion as opposed to Vector2?
@KetraGames
@KetraGames 2 жыл бұрын
Great question. All of the Quaternion methods work for 3D games but you can use them for 2D as well. You can pass in Vector2 values to Vector3 parameters and it will automatically convert the, to a Vector3 with a zero Z value. In this video we used Vector3.forward for one of the parameters as there is no concept of forward in 2D games. You have up and down, and left and right, but no forward and back. For a 2D game, forward is always pointing into the screen, Vector3(0, 0, 1). Instead of Vector3.Forward we could have used transform.Forward and it would have the same result.
@facundoperezsabatini3332
@facundoperezsabatini3332 3 жыл бұрын
thank you so much, this really helped me. But is there any way to also rotate the transform while rotating?
@KetraGames
@KetraGames 3 жыл бұрын
Hi, do you mean that you always want to move in the direction the character is facing? If so, you can change it so the player input only influences the rotation direction. Then when changing the position use transform.forward as the direction
@tarkerro
@tarkerro 2 жыл бұрын
When i rotate my pixel art sprites it's distorted if the angle is not a multiple of 90. What am i doing wrong?
@KetraGames
@KetraGames 2 жыл бұрын
Hi, this can be an issue with pixel art. This article explains the issue - blog.unity.com/technology/pixel-perfect-2d#com There is a Unity package that can help with this though. docs.unity3d.com/Packages/com.unity.2d.pixel-perfect@1.0/manual/index.html Hope that helps you solve the issue 😊
@christiannichols9871
@christiannichols9871 2 жыл бұрын
@@KetraGames I'm having the same issue. I've installed the pixel perfect asset and read the documentation which shows that if you leave the Upscaled Textures unchecked the pixels will rotate with the image, however when I leave it unchecked and follow the tutorial the image is still distorted. I'm at a loss as to what I need to do to make it work the right way.
@ademademov1861
@ademademov1861 11 ай бұрын
What if the starting rotation is not strict, I mean not 0, 90, 180 or 270 degrees?
@pkuuuu
@pkuuuu Жыл бұрын
It works, but the character keeps facing the top, is it normal? How can I fix it?
@LuckyEcho
@LuckyEcho 10 ай бұрын
thanks
@stefankaj442
@stefankaj442 Жыл бұрын
mine is mixed up when i press down it goes up and rotated wrong way
@TitikUniverse
@TitikUniverse 3 жыл бұрын
Господи большое спасибо вам, я делаю игру и хочу сделать поворот летающего корабля в точку Vector2. И я не могу это сделать уже пол года. А теперь я смогу это сделать. Спасибо
@KetraGames
@KetraGames 3 жыл бұрын
Приятно это слышать. Спасибо за ваш комментарий 😊
@enzilla3973
@enzilla3973 8 ай бұрын
does this work with a non-player object?
@blasen_schlampe1108
@blasen_schlampe1108 2 жыл бұрын
what if I wanted to use only the left and right buttons
@KetraGames
@KetraGames 2 жыл бұрын
Hi, if you only want to move left and right then you can just leave out the part about the input from the Vertical axis. Hope that helps 😊
@acrow4969
@acrow4969 9 ай бұрын
idk wtf it is im doing but my up and down only go up and my side to side on go down
@thomb.9013
@thomb.9013 3 жыл бұрын
i rotate my object, and it suddenly doesnt move correctly.(my movement doesnt use the rotation of the object so it should be unchanged but it isnt)
@KetraGames
@KetraGames 2 жыл бұрын
Hi, how are you moving the object? Have you tried copying the script from here - dotnetfiddle.net/zyxR2c ?
@nikitafilatov6723
@nikitafilatov6723 2 жыл бұрын
thank u so much)) u awesome)))
@KetraGames
@KetraGames 2 жыл бұрын
Thank you 😊
@ThiagoPrego
@ThiagoPrego 2 жыл бұрын
Thank you. May the Lord bless you always.
@KetraGames
@KetraGames 2 жыл бұрын
Thank you 😊
@cr4gdcreator893
@cr4gdcreator893 3 жыл бұрын
Noice
@Montazeran8
@Montazeran8 2 жыл бұрын
❤❤❤❤❤❤❤❤❤❤❤❤
@KetraGames
@KetraGames 2 жыл бұрын
👍😊
@yonosenaipe8490
@yonosenaipe8490 2 жыл бұрын
You are GOD
@KetraGames
@KetraGames 2 жыл бұрын
😂Thank you 😊
@befree9390
@befree9390 3 жыл бұрын
Here it is using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerMovement : MonoBehaviour { [SerializeField] private float speed; [SerializeField] private float rotationSpeed; void Update() { float horizontalInput = Input.GetAxis("Horizontal"); float verticalInput = Input.GetAxis("Vertical"); Vector2 movementDirection = new Vector2(horizontalInput, verticalInput); float inputMagnitude = Mathf.Clamp01(movementDirection.magnitude); movementDirection.Normalize(); transform.Translate(movementDirection * speed * inputMagnitude * Time.deltaTime, Space.World); if (movementDirection != Vector2.zero) { Quaternion toRotation = Quaternion.LookRotation(Vector3.forward, movementDirection); transform.rotation = Quaternion.RotateTowards(transform.rotation, toRotation, rotationSpeed * Time.deltaTime); } } }
@tetelp7656
@tetelp7656 3 жыл бұрын
Thank you
@pitchfire7959
@pitchfire7959 2 жыл бұрын
I had jitter but this fixed it. kzbin.info/www/bejne/sGfTnZyEoZmDfbc
@pitchfire7959
@pitchfire7959 2 жыл бұрын
I also had a weird glitch where if my player was hit by a game object it would cause my player to move in the opposite direction of the hit, but this fixed that as well.
@KetraGames
@KetraGames 2 жыл бұрын
Thanks for sharing 😊
@Blackmamba136
@Blackmamba136 2 жыл бұрын
Thank you very much!
@KetraGames
@KetraGames 2 жыл бұрын
👍😊
Unity Movement [RigidBody vs Translate]
9:00
Press Start
Рет қаралды 286 М.
Rotating a Character in the Direction of Movement (Unity Tutorial)
7:25
How many people are in the changing room? #devil #lilith #funny #shorts
00:39
Мен атып көрмегенмін ! | Qalam | 5 серия
25:41
Леон киллер и Оля Полякова 😹
00:42
Канал Смеха
Рет қаралды 4,3 МЛН
How to Rotate in Unity
16:10
Game Dev Beginner
Рет қаралды 29 М.
TOP DOWN Movement - Unity Tutorial
16:17
Sasquatch B Studios
Рет қаралды 17 М.
I Made the Same Game in 8 Engines
12:34
Emeral
Рет қаралды 4,3 МЛН
Create Melee Attack / Combat in Unity - P1 - Attack Animation
16:05
Sunny Valley Studio
Рет қаралды 54 М.
Bringing My Cozy Isometric Game to Life | Hooked DEVLOG #2
22:10
Lost Game Dev
Рет қаралды 159 М.
Pixel Art Tips from a Professional Artist - Tips & Tricks
8:01
Goodgis
Рет қаралды 1,1 МЛН
Much bigger simulation, AIs learn Phalanx
29:13
Pezzza's Work
Рет қаралды 2,8 МЛН
Let's Create: Asteroids in Unity
31:59
Firnox
Рет қаралды 5 М.
Why to use Normalize in Unity ?
13:38
Eincode
Рет қаралды 19 М.