Very concise and well explained. Thank you! One challenge I've had with this top down game mechanic like this is how to deal with aiming the weapon opposite the direction that I'm moving. This happens both with the "aim at mouse cursor + WASD movement" and the dual stick xbox "left stick moves, right stick aims" control schemes. Any chance you have a video coming out to solve that challenge?
Hi Mark, thanks for your support 😊 The plan for this series was to have the player shoot in the direction it's moving, but thinking about it, it's probably also worth including 'aim at mouse cursor' as an alternative control mechanism. It'll be while before we get to it though so in the meantime this code extract may help private void RotateInDirectionOfCursor() { Vector3 mouseWorldPosition = _camera.ScreenToWorldPoint(_mousePosition); Vector2 targetDirection = mouseWorldPosition - transform.position; targetDirection.Normalize(); Quaternion targetRotation = Quaternion.LookRotation(transform.forward, targetDirection); var rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, _rotationSpeed * Time.deltaTime); _rigidbody.MoveRotation(rotation); } To aim at the cursor you need to convert the mouse position to world space. Then you can work out the direction the cursor is from the player. Finally you can rotate towards this target direction in the same way as this video. Hope that helps 😊
@@KetraGames Thank you so much for including this code snippet, I'm trying to include right stick controller rotation using the new input system and I'm kinda having a hard time figuring out how to use that when controller input is detected.. Is there any chance I could get some pointers?
Whenever I press the right arrow key, it faces downward and not right. Same thing for the left arrow key except that it turns upward. And whenever I press the up arrow key, it faces left. Is there any chance that this code doesn't work in version 2021.3.16f1?
Hi, is your character facing upwards towards the top of the screen before you press play? The parent Player object should have no rotation and the child graphics object should be rotated by 90 degrees
I've copied the code from the website you guys provided but I cannot get the model rotating even after triple checking the code. Is there anything else that could stop it from rotating?
One question here: when I go to visual studio and select the codes then hit "quick actions and..." the program says that "no quick actions avaible here". Any suggestions what did I do wrong? Anyway, great tutorial, thanks a lot for it! I would like to see a movement tutorial, where you can learn a simple rpg game movement with animation, that would be cool too!
Hi, not sure why you aren't getting the quick actions. Have you selected the code you want to apply the action to? If you can't get it to work then you can do it by hand. It's just not as quick 😊
Hello Ketra Games! I am at an impasse about the movement of the sprite. My game's sprite has four different sprites that have four unique walking animations for each direction, being up, down, left and right. Meanwhile, yours has the one with animation, which rotates in whatever direction the player will go in. Is there anyway I can set up this movement while keeping the four animations? I wanted to see before actually doing all the work, just in case if it doesn't. Thank you.
Hi, I think you'll probably want to skip this rotation step and instead swap to the relevant animation depending on the direction of input. Hope that helps 😊
Hi, we'll cover this at a later point in the series. If you can't wait then the full project, including rotate toward mouse, is available to our 'All Access' Patrons here - www.patreon.com/posts/full-project-for-75231350 😊
Hi, if you can't get the quick refactoring to work, then you can just copy the changes manually. It's not as quick but as long as the end result is the same then it will work. Hope that helps 😊
@@PungPortal Yes, unfortunately those background are no longer available. We created a similar one here - drive.google.com/file/d/1ACDZNthP0vIpFLBOLvJbI6uIVhM_IEGo/view?usp=sharing. Or you can use any other background image you like 😊
I have a question, is it possible instead of rotating to the direction you are looking, to rotate to the mouse position? I have tried to do it myself, but it didn't work :P.
Hi, we'll cover this at a later point in the series. If you can't wait then the full project, including rotate toward mouse, is available to our 'All Access' Patrons here - www.patreon.com/posts/full-project-for-75231350 😊
Assets\playerscript\PlayerMovement.cs(4,19): error CS0234: The type or namespace name 'InputSystem' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?) Assets\playerscript\PlayerMovement.cs(52,25): error CS0246: The type or namespace name 'InputValue' could not be found (are you missing a using directive or an assembly reference?) I HAVE THIS ERRORS, PLS HELP ME TY
This is bunk...The code doesn't work. I have spent days now trying to figure out why I cannot even get the player to move...thought this would expand upon it. But no. Your code doesn't work. ...
Hi, sorry to hear that it's not working for you. Here are some suggestions for things to check 1. Are there any errors in the console window? 2. Have you installed the new input system from the Package Manager 3. Have you added the Player Input component to the Player and assigned the actions? Hope that helps 😊
🎯 Key Takeaways for quick navigation: - The video introduces how to make a game object rotate to face the direction it's moving in. - The video uses a 2D top-down shooter game as an example. - The video provides two ways to rotate a sprite: using a photo editing application or using Unity. - The video explains how to extract the movement logic into a method called "Set Player Velocity". - This method is used to set the velocity of the player object. - Extracting the movement logic into a method makes the code more organized and easier to understand. - The video explains how to rotate the player object in the direction of input using the "Look Rotation" method. - The "Look Rotation" method takes two parameters: the desired forward direction and the desired up direction. - The video explains that the forward direction is not relevant for 2D games, so the current value is used. - The video explains that the up direction is set to the direction the player is moving. Made with HARPA AI
I can't believe unity doesn't have a simple character controller you can drop into a game and use right away. That is very bad for an engine this popular.
Absolutely in love with your tutorials.
Thank you 😊🥰
Can't wait for the shooting part! Hope it comes out soon!
It's not too far away 😊
Very concise and well explained. Thank you!
One challenge I've had with this top down game mechanic like this is how to deal with aiming the weapon opposite the direction that I'm moving. This happens both with the "aim at mouse cursor + WASD movement" and the dual stick xbox "left stick moves, right stick aims" control schemes. Any chance you have a video coming out to solve that challenge?
Hi Mark, thanks for your support 😊
The plan for this series was to have the player shoot in the direction it's moving, but thinking about it, it's probably also worth including 'aim at mouse cursor' as an alternative control mechanism. It'll be while before we get to it though so in the meantime this code extract may help
private void RotateInDirectionOfCursor()
{
Vector3 mouseWorldPosition = _camera.ScreenToWorldPoint(_mousePosition);
Vector2 targetDirection = mouseWorldPosition - transform.position;
targetDirection.Normalize();
Quaternion targetRotation = Quaternion.LookRotation(transform.forward, targetDirection);
var rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, _rotationSpeed * Time.deltaTime);
_rigidbody.MoveRotation(rotation);
}
To aim at the cursor you need to convert the mouse position to world space. Then you can work out the direction the cursor is from the player. Finally you can rotate towards this target direction in the same way as this video.
Hope that helps 😊
@@KetraGames Thank you so much for including this code snippet, I'm trying to include right stick controller rotation using the new input system and I'm kinda having a hard time figuring out how to use that when controller input is detected.. Is there any chance I could get some pointers?
@@KetraGames Thank you, this code extract helped me out immensely!
Hi, so I have my main camera following the player, is there a way so the camera doesnt rotate when the sprite rotates?
Don't put your camera inside the player. Create a script that moves the player to the camera.
first! u are so good
👍Thank you 😊
Great video!
👍😊
What happened to the other videos in this playlist? I wanted to finish the tutorial :(
Hi, the other videos haven't been released yet. We're making them as fast as we can 😊
@@KetraGames oh, my mistake 😅
Whenever I press the right arrow key, it faces downward and not right. Same thing for the left arrow key except that it turns upward.
And whenever I press the up arrow key, it faces left.
Is there any chance that this code doesn't work in version 2021.3.16f1?
Hi, is your character facing upwards towards the top of the screen before you press play? The parent Player object should have no rotation and the child graphics object should be rotated by 90 degrees
@@KetraGames I have the same problem and the character is facing right
@@KetraGamesNevermind i fixed it, i just changed the graphics z rotation to 90
Thanks for your videos, they are awesome!
Thanks for this comment 😊
I've copied the code from the website you guys provided but I cannot get the model rotating even after triple checking the code. Is there anything else that could stop it from rotating?
Hi, some people have reported issues using the MoveRotation method. Try changing it to SetRotation. Hope that helps 😊
@@KetraGames It helped! thanks
One question here: when I go to visual studio and select the codes then hit "quick actions and..." the program says that "no quick actions avaible here". Any suggestions what did I do wrong? Anyway, great tutorial, thanks a lot for it! I would like to see a movement tutorial, where you can learn a simple rpg game movement with animation, that would be cool too!
Hi, not sure why you aren't getting the quick actions. Have you selected the code you want to apply the action to? If you can't get it to work then you can do it by hand. It's just not as quick 😊
@@KetraGames Thanks 😊
Hello Ketra Games! I am at an impasse about the movement of the sprite. My game's sprite has four different sprites that have four unique walking animations for each direction, being up, down, left and right. Meanwhile, yours has the one with animation, which rotates in whatever direction the player will go in. Is there anyway I can set up this movement while keeping the four animations? I wanted to see before actually doing all the work, just in case if it doesn't. Thank you.
Hi, I think you'll probably want to skip this rotation step and instead swap to the relevant animation depending on the direction of input. Hope that helps 😊
how do i make it rotate towards the mosue?
Hi, we'll cover this at a later point in the series. If you can't wait then the full project, including rotate toward mouse, is available to our 'All Access' Patrons here - www.patreon.com/posts/full-project-for-75231350 😊
How do you do this if you didnt do the smooth input.
Can you help me.. Cause i dont get the quick action refactoring? I did the same as you
Hi, if you can't get the quick refactoring to work, then you can just copy the changes manually. It's not as quick but as long as the end result is the same then it will work. Hope that helps 😊
@@KetraGames I got it and I did it thank you 🔥.. Btw I didn't get the 12 2D free background assets about the battle background .. Is it over or how?
@@PungPortal Yes, unfortunately those background are no longer available. We created a similar one here - drive.google.com/file/d/1ACDZNthP0vIpFLBOLvJbI6uIVhM_IEGo/view?usp=sharing. Or you can use any other background image you like 😊
I am trying to follow along but I keep getting the same error that quaternion dose not contain a definition for RotateTowards
Hi, have you tried copying the code from here? dotnetfiddle.net/6DWkDw
Hey , Everything worked fine but rotation is weird , like it rotates suddenly and looks so much weird , any idea how to fix this ?
Hi, some people have reported issues using the MoveRotation method. Try changing it to SetRotation. Hope that helps 😊
Hi @nmd2899 The problem is that the player input and the player image are not in the same location.
great video but my character is 90 degrees off; if i move left then it looks up and if i move up it looks right, can you help
😆
I have a question, is it possible instead of rotating to the direction you are looking, to rotate to the mouse position? I have tried to do it myself, but it didn't work :P.
Hi, we'll cover this at a later point in the series. If you can't wait then the full project, including rotate toward mouse, is available to our 'All Access' Patrons here - www.patreon.com/posts/full-project-for-75231350 😊
@@KetraGames Okay, thanks for your explanation :D
Assets\playerscript\PlayerMovement.cs(4,19): error CS0234: The type or namespace name 'InputSystem' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)
Assets\playerscript\PlayerMovement.cs(52,25): error CS0246: The type or namespace name 'InputValue' could not be found (are you missing a using directive or an assembly reference?)
I HAVE THIS ERRORS, PLS HELP ME TY
Hi, have you installed the Input System package from the package manager?
It says 2 of the videos are currently hidden. Are the hidden videos intended for patreons?
Hi, no they were deleted videos that were still in the playlist somehow. We've now removed them. Thanks for letting us know 😊
very good , but i still dont understand why the child , and how it doesnt work if we dont have the child object to the player
its not working, i follow all the instruction, even i coppy ur code still not working, i am already install inputSystem too
almost what i want :( but only rotates rigidbody not gameobjects
the exract method is not working!
Hi, if that option isn't available you can just manually change the script to match. It will take a bit longer but it should still work 😊
@@KetraGames i cant change the "private void fixedupdate" into setplayervelocity.. how can i fix it
The Final script have errors
Hi, what errors are you seeing? Can you compare yours with the final script here to see if there are any differences? - dotnetfiddle.net/6DWkDw
This is bunk...The code doesn't work. I have spent days now trying to figure out why I cannot even get the player to move...thought this would expand upon it. But no. Your code doesn't work.
...
Hi, sorry to hear that it's not working for you.
Here are some suggestions for things to check
1. Are there any errors in the console window?
2. Have you installed the new input system from the Package Manager
3. Have you added the Player Input component to the Player and assigned the actions?
Hope that helps 😊
🎯 Key Takeaways for quick navigation:
- The video introduces how to make a game object rotate to face the direction it's moving in.
- The video uses a 2D top-down shooter game as an example.
- The video provides two ways to rotate a sprite: using a photo editing application or using Unity.
- The video explains how to extract the movement logic into a method called "Set Player Velocity".
- This method is used to set the velocity of the player object.
- Extracting the movement logic into a method makes the code more organized and easier to understand.
- The video explains how to rotate the player object in the direction of input using the "Look Rotation" method.
- The "Look Rotation" method takes two parameters: the desired forward direction and the desired up direction.
- The video explains that the forward direction is not relevant for 2D games, so the current value is used.
- The video explains that the up direction is set to the direction the player is moving.
Made with HARPA AI
it does not rotate in the direction of input
Hi, does it rotate at all?
I can't believe unity doesn't have a simple character controller you can drop into a game and use right away. That is very bad for an engine this popular.
trying to do this on mac is infuriating
ooga booga
Thanks baby girl
👍😊