Thank you for this tutorial! You explained everything in a normal conversation speed, giving us time to digest what you are saying and doing cursor movements that helps in how you are making your points. /bow
Great tutorial. But... offsetting the angle by -90 deg is not because of Unity. 0 deg starts at 0 on the x-axis and would prove the same for the arrow if the texture started out pointing on the x-axis. The offset is because your arrow's texture starts out pointing on the y-axis and this is where the extra 90 degrees comes from. Just look carefully where the arrow's red x-axis points when you think something is wrong. 12:28
Hi, this 16:37 is basically exactely what i have sofar and need but i need the arrow/sprite facing towards the ever changing mouse position while its being dragged. aka i need the sprite to rotate in direction of drag (without using velocity) any help would be appreciated thanks
for some reason when i entered the code using the eulerAngles i get an error CS1519 saying that the equal sign is an invalid token in class. how to i fix this
The reason why the arrow wasn't initially pointed towards the target is not because of clockwise vs counterclockwise implementation at all (in fact counterclockwise is indeed the positive rotation direction in Unity too). It was simply because the arrow sprite was pointing upwards along the Y axis. Your rotation calculation ends up pointing the X axis of the object towards the target while you wanted to point its Y axis towards the target, and that is why you had to subtract 90 from the calculated angle. If the arrow sprite was aligned with the X axis, then you wouldn't have to do anything to the original calculation.
In the new Vector3 of Camera.main.ScreenToWorldPoint I would most likely use 'Camera.main.transform.position.z * 0' to make sure that it always returns to 0 on Z axis no matter what the number is. Just to be safe in case someone changed the Z position of the camera.
Thank u sir it helps alot to understand vectors , direction and rotation . can u make a video on "Rotations" in unity difference between tranform.EulerAngles and Quterniom.Euler and when should we use either of these....
I have no idea why, but this is totally not working for me. The goal is to have the enemy always face the player. The enemy is using navmesh to walk towards the player (and in that case it automatically rotates towards what it's walking towards). I've tried both the methods you gave, and for some the enemy will warp to facing the left of player (towards the west), and then slowly rotate to face the player (probably by the navmesh?) and then when it's facing the player the rotation will warp back to west (so the enemy is facing to the left of the player). It acts the exact same, regardless of which method I try. I tried removing the -90, changed it to +90, and tried +180, and yet it still does the EXACT same thing, which makes zero sense to me. I've also tried changing the destination.x/y to using Z, since I'm doing this in 3D. However, the results are again the EXACT same, which just boggles my mind. The angle value remains the same as well. You would think adding 90/180 degrees, and changing the axis, would totally change the outcome, but it's consistently doing the same thing. There were a lot of conversions happening in your video, which were obviously needed, but it's probably just something lost in translation that I don't get.
Hello. Did you ever solve your issue? The most helpful thing I ever did to help keep rotation and direction from getting janky, is to restrict the angles from any calculation to be between -180 and 180. This really helps when telling your object to turn right or left. I can provide more explanation if needed.
I don't understand - the mouse cursor one doesn't work? ***UPDATE*** I worked it out - it just doesn't work with UI elements - you need to do something extra for that
@@pattech3960, nevermind I already drove one with paint 3d, images that I got from the internet were not transparent in google, so I used paint 3d and it worked!
How would I calculate the angle if I could only calculate the distance between to objects on the y axis. For example in 2D space, if object1 is falling in a linear direction (no gravity) towards a platform, how would you calculate where object1 will collide with said platform before collision? Btw, I never took this level of math in school, but I understand it the way you teach it, so thank you!
Solid math application here. But.The rotation is done correctly only in second case, with eulerAngles. The slerp is not used as it's meant to be, and it's a shame that even Unity points toward wrong using in their documentation. Lerping methods return the value between two values specified as a parameters, at some point of progress which is 3rd parameter - t [0, 1]. It shows how progressing the return value will get from start to end values. In your implementation you pass 50*Time.deltaTime, which is ~1, so you set the rotation to end value immediately and gives "same" result. Lerping would be applicable if there is a need in changing rotation over time, and as this time would range from 0(start time) to 1(end time) , it will map returning value accordingly from its startValue to endValue. Usually done with coroutines, and not as it is shown in documentation.
🚀 Launch Your Tech Career - *FREE Training:* gamedevhq.com/free
Thanks for watching all! We'd love for you to help our channel grow by sharing it with your groups!
Thank you for this tutorial! You explained everything in a normal conversation speed, giving us time to digest what you are saying and doing cursor movements that helps in how you are making your points. /bow
Best tutorial ever , I would love to see a tutorial of making field view
Best tutorial for this aspect. We want more!!
WOW! I was looking for a tutorial like this for months!!!! truly helpful, i will chek your chanell for more content, TY
Great tutorial. But... offsetting the angle by -90 deg is not because of Unity. 0 deg starts at 0 on the x-axis and would prove the same for the arrow if the texture started out pointing on the x-axis. The offset is because your arrow's texture starts out pointing on the y-axis and this is where the extra 90 degrees comes from. Just look carefully where the arrow's red x-axis points when you think something is wrong. 12:28
Re-watching you're right. This could be resolved through the orientation of the object as well. Thanks for the explanation!!
@@gamedevhq Happy to help! I'm just sorry my comment was as long as a book!
@@alexfish7792 you call that a book? :D Thanks for clarifying!
@@alexfish7792 there exists longer comments
thank you for this comment lmao because i was thinking the same thing
Oh my God! Thanks a lot bro. Finally a straight forward video explaining angles.
Hi, this 16:37 is basically exactely what i have sofar and need but i need the arrow/sprite facing towards the ever changing mouse position while its being dragged. aka i need the sprite to rotate in direction of drag (without using velocity) any help would be appreciated thanks
i tried using transform.Translate(direction, Space.Self); but this makes it rotate 360degrees continousy
Just because of your tuts I start to enjoy coding
for some reason when i entered the code using the eulerAngles i get an error CS1519 saying that the equal sign is an invalid token in class. how to i fix this
The reason why the arrow wasn't initially pointed towards the target is not because of clockwise vs counterclockwise implementation at all (in fact counterclockwise is indeed the positive rotation direction in Unity too). It was simply because the arrow sprite was pointing upwards along the Y axis. Your rotation calculation ends up pointing the X axis of the object towards the target while you wanted to point its Y axis towards the target, and that is why you had to subtract 90 from the calculated angle. If the arrow sprite was aligned with the X axis, then you wouldn't have to do anything to the original calculation.
how i can can create multiple raycasts from object including edges, based on object rotation? imagine if coin on edge or flat on ground..
For Fetching the angle, if you instead of write Mathf.Atan(y/x) to Mathf.Atan(x/y), than it gives the same result. any idea why
GREAT VID BRO !
Thanks bro!
1 minute and 40 seconds in i already understood what's going to happen, thanks so much!
Thank You, your videos are gold :D
Best teacher 😍
Useful tutorial
Thanks for watching!
Thank you so much, well explained ♥
great video as always :)
In the new Vector3 of Camera.main.ScreenToWorldPoint I would most likely use 'Camera.main.transform.position.z * 0' to make sure that it always returns to 0 on Z axis no matter what the number is. Just to be safe in case someone changed the Z position of the camera.
Thank u sir it helps alot to understand vectors , direction and rotation . can u make a video on "Rotations" in unity difference between tranform.EulerAngles and Quterniom.Euler and when should we use either of these....
Amazing work maaan. Thank you so much!!!
Very useful tutorial👍
ILL GIVE YOU A KISS BRO, THANK YOU SO MUCH
Amazing 🤓💙
Well done sir. Always good content ;) thank you.
Thanks for watching!
Can someone explain to me how this is work: Tan -1 (1.25) = 51.34 ?
Where did you get this number: 51.34 because I don't understand this ;(
excellent video! thank you very much!
can't we use of Transform.LookAt(target) ?
Namaste, Transform.LookAt works only for 3d in 2d the Z messes things
Best regards How i print in a canvas the angle of rotation of a game object?
extremely helpful, thanks!
Instead of subtracting just invert the values instead of tan(y/x) we can say Tan(x/y)
That is indeed a.... fast solution!
Are you from brackeys channel ? 😅
Very useful, thank you.
Can you make video on trajectory path prediction
Great super useful tutorial thank you
Hey GameDev! I was wondering if you could make a tutorial on turning joystick input into rotation
Videos such this and calculating direction is not in the "coding math" playlist and seems these videos is not collected in a relevant playlist
Finally someone who pronounces Euler correctly.
YOOLER
It is only works for 2d? In 3d it isn't works
Very useful for those unfamiliar :)
Thank you.
Good tutorial bruh
why do we get 128 instead of 51 ish?
More please
thanks this very amazing
I have no idea why, but this is totally not working for me. The goal is to have the enemy always face the player. The enemy is using navmesh to walk towards the player (and in that case it automatically rotates towards what it's walking towards).
I've tried both the methods you gave, and for some the enemy will warp to facing the left of player (towards the west), and then slowly rotate to face the player (probably by the navmesh?) and then when it's facing the player the rotation will warp back to west (so the enemy is facing to the left of the player).
It acts the exact same, regardless of which method I try. I tried removing the -90, changed it to +90, and tried +180, and yet it still does the EXACT same thing, which makes zero sense to me.
I've also tried changing the destination.x/y to using Z, since I'm doing this in 3D. However, the results are again the EXACT same, which just boggles my mind. The angle value remains the same as well. You would think adding 90/180 degrees, and changing the axis, would totally change the outcome, but it's consistently doing the same thing.
There were a lot of conversions happening in your video, which were obviously needed, but it's probably just something lost in translation that I don't get.
Hello. Did you ever solve your issue? The most helpful thing I ever did to help keep rotation and direction from getting janky, is to restrict the angles from any calculation to be between -180 and 180. This really helps when telling your object to turn right or left. I can provide more explanation if needed.
I don't understand - the mouse cursor one doesn't work?
***UPDATE***
I worked it out - it just doesn't work with UI elements - you need to do something extra for that
Could you please expaint this (Tan -1(1.25)=51.34)
Amazing tutorial bro, can you please send a link to your arrow sprite image, would be much appreciated!
Just install one on the internet as a PNG
@@pattech3960, nevermind I already drove one with paint 3d, images that I got from the internet were not transparent in google, so I used paint 3d and it worked!
@@Skillet367 Ah okay :)
explain trajectory prediction please
Read my mind! ;) Coming out soon!
Wow yeah... Thank you very much :)@@gamedevhq
Awesome:)
Thanks for watching!
Awesome Tutorial
Thanks for watching! We'll see if we can get more demand from it!
john with gemdevichew?
좋은 강좌 감사합니다. ^^
the tiny keyboard sounds are very pleasing mmm
I love you
How would I calculate the angle if I could only calculate the distance between to objects on the y axis. For example in 2D space, if object1 is falling in a linear direction (no gravity) towards a platform, how would you calculate where object1 will collide with said platform before collision? Btw, I never took this level of math in school, but I understand it the way you teach it, so thank you!
not fully following the question. I'd suggest posting your question in our discord channel. gamedevhq.com/discord
👏👏
axis and access are two different words.
Super Cool
🥰🥰🥰🥰🥰🥰🥰🥰🥰
This guy prefers kebabs - burgers make him wein!
Nice Lecture. Good to see some proper math for once.
Solid math application here. But.The rotation is done correctly only in second case, with eulerAngles. The slerp is not used as it's meant to be, and it's a shame that even Unity points toward wrong using in their documentation. Lerping methods return the value between two values specified as a parameters, at some point of progress which is 3rd parameter - t [0, 1]. It shows how progressing the return value will get from start to end values. In your implementation you pass 50*Time.deltaTime, which is ~1, so you set the rotation to end value immediately and gives "same" result. Lerping would be applicable if there is a need in changing rotation over time, and as this time would range from 0(start time) to 1(end time) , it will map returning value accordingly from its startValue to endValue. Usually done with coroutines, and not as it is shown in documentation.
100% agree about Lerp/Slerp! Check this out -> chicounity3d.wordpress.com/2014/05/23/how-to-lerp-like-a-pro/
likes
Wow I've never heard someone mispronounce axis before.
denggggiuuuuuu
Are u indian
Great stuff, thank you
Very helpful! thank you.