How Do I Make a Cube Follow a Path?

How would I make a cube follow a specified path in the BGE? Is it possible to use the “up” key to cause the cube to move forward and the “down” key to cause the cube to move backwards and maybe the “Spacebar” to stop the cube?

Also is it possible to trigger an object to move when the cube moves past a certain point?

Thanks SolarLune. Actually I saw that file last night but I was hoping for something simpler for a newb like me to understand unless there’s a way to simplify your example. :slight_smile:

Is there a way to do it that uses a spline and an object. I want to make the spline the shape of the path and then have the object follow the spline and use the keyboard’s up and down to move the object forward and back etc.

There is no current way to set a spline and get a cube to follow in the BGE. The next best thing (using logic, anyway),is to try one of the following examples:

One uses an IPO thats animated to follow the path you want, and an object that tracks to that ‘target’. On contact the IPO will move on a few frames (see AI_TESTER_ADV).

The other uses nodes and a crude counting method to track to pre-defined nodes (see AI_VER3ex).

If you need any help with these feel free to ask (btw, these are for 2.57, not 2.49b).

When you get better at Python, SolarLunes Python method is better as the logic block approach gets very messy (as you will see!!)

Cheers, and hope it helps you

Paul

Attachments

AI_TESTER_ADV.blend (483 KB)AI_VER3ex.blend (1010 KB)

You mean do it with Flash version?

Hello
as the last versions of Blender ( 2.49, 2.5) have less functions than the old ones, do a search in forum for a path2ipo script and use it with version 2.48, then open the result in a recent one!
Bye

Rubbernuke, hi thanks for the file examples. Could you explain what they are doing. How do I get the object to follow the path. I don’t see a path in the Outliner. When I press the "P’ key the objects just seem to randomly move. How can I get them to follow a specific path?

Thanks schwaberry and OTO. OTO I need to do this in BGE 2.5. :slight_smile:

Up Key = Forward motion
Down Key = Reverse motion
Spacebar = Stops motion

I made a “very simple” cube and added a forward and reverse movement using a “Motion Actuator” controlled by the keyboard “up” and “down” arrows. So far so good, :slight_smile:

Question #1
When I hold the “up key” down the cube moves but how do I get it to stay moving? I want to press the up key once and the cube will start to move. I don’t want to have to “hold” the key down.

Question #2
Is there a “very simple” (I am a newb at this) way to get the cube to trigger a light and sound when the cube reaches a certain point? Keep in mind the cube is just placed at (XYZ 000) and just goes in a straight line for now.

Question #3
I need to use Blender 2.5. Is there any other (simple) way (other than a path since this doesn’t work in 2.5 BGE) to make the cube move in an oval direction like the shape of a indy track. I want it to move like a train fixed to a train track or a car fixed to a roller coaster track. Is it possible to animate this using a curve path and keyframes outside of the BGE and then add keyboard control? Or is there a way to do this in the BGE 2.5 other than using a path?

Question #4
How can I save this file out so it can be used on my website and not in Blender? I still want to use the keyboard keys to control the animation? I hope this makes sense. What kind of file options can I save this as to make this work?

OK,

In the first example, I have animated a cube and recorded its motion using keys. Now, using logic, I have added an f-curve brick that plays the animation (we will call this object ‘target’). The red following objects have logic that makes them follow ‘target’. Target also has a near sensor that triggers when a red following object gets near it; when they get close, the ‘target’ plays a few frames of its motion and goes along its pre-defined path. This continues and the chase objects go round a path as they chase the ‘target’.

In the second example, green cubes called nodes (numbered 1-10) define a path. A chase cube has logic defined thus:

If node property=0 go to node 0
If node property=1 go to node 1 etc, all the way to node 10.

Always move

On collison with a node, node property +1

If node property = 11 (i.e. we have gone around the chain of nodes), we use the amend property to set the node property to 0 (to start again).

You can move the nodes around to define your path and when you press P the chase object will track to the path defined. In the example 8 cars are racing around the track, following this node path.

Hope that helps

Paul

OK, thanks for explaining that Rubbernuke. This stuff can be confusing. :slight_smile:

I made a “very simple” cube and added a forward and reverse movement using a “Motion Actuator” controlled by the keyboard “up” and “down” arrows. So far so good, :slight_smile:

Up Key = Forward motion
Down Key = Reverse motion
Spacebar = Stops motion

Question #1
When I hold the “up key” down the cube moves but how do I get it to stay moving? I want to press the up key once and the cube will start to move. I don’t want to have to “hold” the key down.

Question #2
Is there a “very simple” (I am a newb at this) way to get the cube to trigger a light and sound when the cube reaches a certain point? Keep in mind the cube is just placed at (XYZ 000) and just goes in a straight line for now.

Question #3
I need to use Blender 2.5. Is there any other (simple) way (other than a path since this doesn’t work in 2.5 BGE) to make the cube move in an oval direction like the shape of a indy track. I want it to move like a train fixed to a train track or a car fixed to a roller coaster track. Is it possible to animate this using a curve path and keyframes outside of the BGE and then add keyboard control? Or is there a way to do this in the BGE 2.5 other than using a path?

Question #4
How can I save this file out so it can be used on my website and not in Blender? I still want to use the keyboard keys to control the animation? I hope this makes sense. What kind of file options can I save this as to make this work?

  1. When you press Up, use the State actuator to switch states, in which you provide a motion forwards.
  2. The Sound actuator and (maybe) an Add Object actuator set to a light in a hidden layer would work for these.
  3. You could animate it yourself using F-Curves, and then use the F-Curve animation to animate the path.
  4. You’d need to use the Burster web plugin to enable this - you’ll have to be on a Windows or Mac, I think. Google Burster to find out more info.

Thanks SolarLune :slight_smile:

I have already done that. I have a motion forward set to the “up key” but it only moves when I “hold” the up key down. I want to tap the “Up Key” and the object will move. I don’t want to have to hold the up key down for it to move. Sorry if I don’t understand.

Thanks. I will try that.

Thanks but I do mostly modeling and have never done this before. Do you know where I could find more information on how to do this?

They have no mac version. Is there any other way I can have a user use the game without having them do it in Blender?

Yes, i think you can compile a runtime, try enabling the option in the add-ons menu.