How do I rotate things (e.g. (for example), Kinebodies, bitmaps, rigidbodies, etc.)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Guy

–rotate things with arrow keys.

Perhaps you could change your question title to include the bit about using arrow keys to rotate?
e.g., “How do I rotate things with the arrow keys (Kinebodies, Bitmaps, etc?)”

Then people could find your post when they have a similar question. It would help out a lot! :wink:

Yuminous | 2021-07-08 09:20

:bust_in_silhouette: Reply From: Yuminous

You can do this in a few ways.

Here’s one way using the default Project Settings > Input Map bindings:

var object = $NodeObject
var rotation_speed = Vector3(1, 0, 0)  # rotate the X-axis at 1 radian/tick

func _physics_process(delta):
    if Input.is_action_pressed("ui_left"):
        object.rotate(rotation_speed)
    elif Input.is_action_pressed("ui_right"):
        object.rotate(-rotation_speed)  # note the '-' to reverse rotation

Alternatively you directly specify the buttons with Input.is_key_pressed(KEY_LEFT)
You can consult the keylist for info on the names to use for that.

Another method involves using the _input or _unhandled_input functions, like:

# note this method uses a different way of specifying the Node and a way to 
# rotate it, you could do the same with the above example or vice-versa.
func _unhandled_input(event):
    if event.is_action_pressed("ui_left"):
        $NodeObject.rotate_x(1)
    elif Input.is_action_pressed("ui_right"):
        $NodeObject.rotate_x(-1) 

Just be aware with this method that _input functions do not precisely control their loop frequency like _physics_process does, so the result can be extremely fast or slow based on how good the target system is. You can add timers, but for something quick to test stuff it’s absolutely fine.

Good luck!