Godot 4 - How to Rotate Smoothly to Face a Direction
Автор - Thomas Yanuziello
ссылка -
От автора:
You have a character or other object that you want to face a specific direction, possibly the direction the player wants to move, either in 2D or 3D. But you want the rotation to be smooth over time, not just instantly snap to the direction.
Start by exporting a rotation speed, a float measured in radians per second.
If radians make no sense to you, you can define it as a multiple of PI or TAU. PI is a half circle, or 180 degrees, and TAU is a full circle, or 360 degrees. I’ll use TAU times 2, which is 2 full rotations per second. Also define a variable that represents the angle between the direction they are currently facing, and the direction we want them to face, THETA.
If the player is giving direction input, then we can calculate THETA to be atan2 of y over x. This provides the angle difference of a line segment connecting the origin of a 2D cartesian plane to these coordinates and the positive x axis. Subtracting the current rotation gives us the difference between that line segment and the current rotation. We also need to wrap this value to be between negative and positive PI. Remember that PI is a half rotation, so this is restricting the angle to be between a half rotation clockwise and a half rotation counterclockwise.
Then add to the character’s rotation, the rotation speed times DELTA, clamped to be no less than 0, and no more than the absolute value of THETA. This will prevent overshooting the mark, since the actual rotation can’t be more than theta. But we also need to apply the sign of THETA to the rotation speed, to rotate in the desired clockwise or counterclockwise direction.
In 3D, we are rotating the character rig, and its rotation is a vector3, but we only need to rotate about the y axis. We can use the same formula, substituting -z for y in the direction if using 3D direction, but also adding a quarter rotation, making backward, or away from the camera, the point of reference instead of right. Or we can simplify this a little bit by removing the quarter rotation, swapping x and z in the atan2 function, and removing the negative from z. This will still provide the angle difference between the directional input and the character rig’s current y rotation, so the rotation statement remains the same.
3D assets made by KayKit
70 views
484
129
8 months ago 00:03:07 0
5 Months in Tutorial Hell: What I Learned
9 months ago 00:03:32 3
Какая недвижимость подходит для получения турецкого гражданства?
9 months ago 00:15:56 1
Blender-Godot Pipeline V2.4 || Blender Asset Library and Packed Scene Generation
9 months ago 00:26:58 0
How Good Can I Make Godot Look 2 - The Cellar
9 months ago 00:43:16 0
Phoenix Wright: Ace Attorney Piano Album (Gyakuten Saiban 逆転裁判ピアノ BGM)
9 months ago 00:19:48 0
Всё о Tilemap в Godot Engine 4
9 months ago 00:40:32 0
[New] GODOT 4 - Projectiles VFX ( FIRE BALL )
9 months ago 00:04:55 2
Horror Game Environment Tutorial - Godot 3D
9 months ago 00:05:46 0
Short Stories #4: Павел Дрожко - долгая дорога к разряду
9 months ago 00:02:17 0
She is f**king crazy..
9 months ago 00:00:28 0
К концу года ты погасишь все свои долги и кредиты!Ты заработаешь много денег! 💰Жми❤Миа🧚♀️💷💴💵💴💵💷💴💵💴💴
9 months ago 00:00:44 1
Как улучшить камеру в играх / Плавное движение камеры
9 months ago 00:00:51 0
Экспорт HTML5 игр на / Godot Engine
9 months ago 00:27:08 0
Масс-маркет и средний сегмент: примеры маркетинга, VM и сервиса
10 months ago 00:06:54 3
Improving Environment Graphics in Godot 4 - Tutorial
10 months ago 00:02:46 2
Jungle Demo V2 - Godot Engine 4
10 months ago 00:06:57 13
ОБЛОЖКА КАК У 3TERNITY | Обложка в DAZ STUDIO 3D | ЧАСТЬ 5
10 months ago 00:18:02 0
Hitscan Weapons - Making an FPS Manager in Godot 4 P3
10 months ago 00:02:13 0
#11 (Информационная среда и платформы, блокировки, агрессивная риторика)
10 months ago 00:09:26 0
NEW Procedural Animation In Godot 4.0
10 months ago 00:14:10 0
Как начать делать ИГРЫ в GODOT 4 | Урок 1 | Самый подробный курс по Годот для начинающих с нуля!