Car tutorial - are the wheels supposed to leave the car?

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.
Capture

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)

Naturally, shortly after posting, I tracked it down, after wasting hours looking at it prior… During the positioning step, I positioned the sprites, and not the wheel game objects. so it was rotating the game object which was centered on the car, but the sprites would swing further due to the angle of their parent game object.

1 Like

I am not an expert when it comes to driving but usually the wheels are supposed to stay attached to the cars at all times - even when parked.

Well done for getting this sorted!

1 Like