How to rotate an object from its center origin?

Version 4.3

hi,

i’am quiet new to godot and already struggling with a supposedly easy task.

with the help of gridmap object i was able to create a 16 x 16 map (dynamically) filled with cubes (meshes, not visible in the editor). did setup an orthogonal camera with rotation (-30, -45, 0) values for an isometric look. the tree looks like this:

game (main scene)

  • directional light
  • camera3D
  • gridmap

gridmap (single scene)

  • node3d
    – gridmap (here’s my script)

now, in my gridmap script i want to rotate the gridmap on the y-axis when a key is pressed, looks like this:


var gridmap_rotation : int = 0

func _input(event):
if Input.is_action_just_pressed(“rotate_left”):
var tween = create_tween() # for a transition
gridmap_rotation += 90 # need to fix this as well
tween.set_trans(1)
tween.tween_property(gridmap, “rotation_degrees”, Vector3(0, gridmap_rotation, 0), 0.5)


the problem: it is rotating the gridmap at point (0, 0) (top left), not from the center.

how can i rotate my gridmap object from its center origin?

I believe you need to:

  1. Add a parent node to the gridmap
  2. Move the gridmap relative to the parent, by half of its size on each axis
  3. Rotate the parent instead of the gridmap

Hopefully that makes sense.

1 Like

hi gentlemanhal,

yes it does. it is working, thanks for your input. : -)

have a nice day!

1 Like