For 2D, you can rotate a Node2D using the rotation
or rotation_degrees
properties. This will rotate the Node2D around it's pivot point, which is generally the center of the sprite/image/entity.
For 3D, there are a few ways to rotate a Spatial node, depending on what you are wanting to do. To rotate the Spatial node around a single axis, you can use the rotate_x
, rotate_y
, and rotate_z
functions. You can also rotate an object using the rotate
for world-space rotations, and rotate_local
for local-space rotations. You can also use the look_at
function to have the Spatial node rotate itself to look at the inputted position.
(In 3D, you can also rotate the Basis in the transform of the spatial if you want, but for most cases this is not necessary)
If you want to rotate the object relative to a collision, you might want to look into using test_move
, and then use the normal (and perhaps relative velocity) to calculate the angle and amount of rotation. Last I knew, KinematicBody2D and KinematicBody nodes to not have a function to rotate based on collision results.
You might be able to use a RigidBody2D/RigidBody node set to Kinematic, but I haven't tried it myself so I do not know how feasible it would be. There is a demo on the Godot demo repository that uses a RigidBody2D-based character that might help if you decide to use a RigidBody instead.