# Making a car game opponent

I was making a go kart game and I need an opponent. is it possible that I use a follow track but when I touch the car it will affect him?

• So to clarify, you want to have a (rigid body?) object try to follow a path, but allow it to be pushed around by other collision objects? Commented Aug 22, 2015 at 20:48
• Yes, I want to make the object follow a curve/path and allow it to be pushed around. If it goes of the curve but it should align itself again. Commented Aug 22, 2015 at 21:38
• Maybe you have to code it the way that if the car goes of the track it tries to allign with the track again and then follows it. And probably that it tries to allign with the track whilst driving forwards on the road not that it drives completely "horizontal" on the track. Commented Aug 23, 2015 at 15:39
• But I don't know how. Commented Aug 23, 2015 at 19:33

Here is a "simple" solution.

It involves two objects. A vehicle and a "waypoint jumper".

It is a kind of "Carrot on a stick" approach. The vehicle follows the waypoint . When the vehicle collides with the waypoint it jumps to the next waypoint location -> "waypoint jumper".

Vehicle

You are free to create an vehicle as you like. It needs to have two operations:

1. move forward
2. turn towards the waypoint jumper

here is an example:

I'm sure you have your own version of the vehicle. Just ensure it turns and moves forward all the time.

To make the vehicle detectable add a property car

The type does not matter. It has no further purpose. It just should exist at the vehicle.

Waypoint jumper

We need an object that can detect the vehicle from a certain distance. I suggest to use a mesh object that detects collisions with the vehicle. A plane or circle should be fine.

To avoid stopping the vehicle the object gets Physics type Sensor.

When you have the object you can define the waypoints. Create an action with location keyframes at subsequent frames (1,2,3,4...). You do not need fine granularity. Just ensure the direct line between waypoints is not blocked and there is enough space for turns.

The jumper should know what the current waypoint is. We store it as property 'frame' a whole number, starting with the first frame.

First we play the current waypoint position. We do not need to do that all the time - only on startup or when the waypoint changes. We let the waypoint jumper play the pose according given by the property frame.

When the car comes near we switch to the next frame. If the car happens when it collides with the mesh. We filter collisions by property car, to exclude any accidental collisions with other objects.

Now you can start your game engine and watch your vehicle follow the carrot ... waypoint jumper.