I don't understand rotation
Asked Answered
B

1

0

I am very new to Godot but I have been doing unity for a wile. I am making an evolution simulator similar to Conway's game of life. I made a script for generating organisms and now I was to make them move, but I want them to snap to grid, it works until I try rotating them. I rotate it but it still moves in the same direction. any ideas on how to make this work?

Blankenship answered 6/1 at 19:32 Comment(0)
S
0

Rotation isn't tied to Position. Rotation is simply the angle offset of the node and Position is simply the pixel coordinate of the node.

If you want your objects to move in the direction of the Rotation, try adding Transform.x or Transform.y to your Position. I believe the Transform property is commonly used in Unity to move objects in the direction they are facing.

Transform.x is the objects orientation based on the X-axis and Transform.y is for the Y-axis. It returns a Vector based on the objects Position, Rotation and Scale. If you add Transform.x to your Position, and your node has no rotation, it will move to the right. If it has a 90 degree rotation, it will move downward, etc.

Example:
position += transform.x * grid_size

If your cell has, say, a 180 rotation and the grid size is 16, your cells should now move 16 pixels to the left. I hope this helps.

Sedimentology answered 6/1 at 20:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.