I was working through the car tutorial because i’ve been trying to wrap my head around how to handle rotating a game object as its moving. In my case, I’m just having my game objects move along a set of co-ordinates, and as it reaches the next waypoint, I want it to start turning towards the waypoint beyond it.
The car tutorial seemed like it would explain some of that (handling rotation & velocity), however in following it, the wheels completely leave the car when it turns.
I’m assuming this is because its rotating around its 0,0 which happens to be the left or right corner instead of its center point, but I don’t really know how to solve that. Did i miss something in the tutorial (i’ve re-read it 3 times…)
Is there a better example of how to handle a game objects movement & direction? I know in general to make something face another, i use the atan2, quat_rotation_z stuff (code snippet below), and that works but it rotates the object around its middle which looks weird. I was aiming for something more like what the car does where it calculates front and back wheel locations so the turn looks more natural
--handle rotation
direction = vmath.vector3(tank_path[self.going_to][1], tank_path[self.going_to][2],pos.z) - pos
angle = math.atan2(direction.y, direction.x)
rotation = vmath.quat_rotation_z(angle)
go.set_rotation(rotation)