1
$\begingroup$

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?

$\endgroup$
4
  • $\begingroup$ 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? $\endgroup$ – gandalf3 Aug 22 '15 at 20:48
  • $\begingroup$ 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. $\endgroup$ – Hendriks3D Aug 22 '15 at 21:38
  • $\begingroup$ 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. $\endgroup$ – Jonathan Aug 23 '15 at 15:39
  • $\begingroup$ But I don't know how. $\endgroup$ – Hendriks3D Aug 23 '15 at 19:33
2
$\begingroup$

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:

enter image description here

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

enter image description here

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.

enter image description here

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

enter image description here

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.

enter image description here

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

enter image description here

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.

enter image description here

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.

enter image description here

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.