Game Development Reference
In-Depth Information
How to do it...
Let's begin by creating a platform object to move, by performing the following steps:
1. We define a new Geometry called platform and apply the Unshaded materi-
al to it, as shown in the following code:
platform = new Geometry("Platform", new Box(1f, 0.1f,
1f));
platform.setMaterial(new Material(assetManager,
"MatDefs/Misc/Unshaded.j3md"));
2. Then, we attach the platform object to rootNode .
3. Next, we define a new MotionPath object called path .
4. We add 8 waypoints in a circular pattern, using the following code:
for(inti = 0 ; i< 8; i++){
path.addWayPoint(new Vector3f(0,
FastMath.sin(FastMath.QUARTER_PI * i) * 10f,
FastMath.cos(FastMath.QUARTER_PI * i) * 10f));
}
5. Then, we call path.setCycle(true) to make it connect the first and last
waypoints.
6. Now, we can define a new MotionEvent called event and supply platform
and path in the constructor.
7. We call event.setInitialDuration(10f) and setSpeed(1f) .
8. Finally, we call event.setLoopMode(LoopMode.Loop) .
Search WWH ::




Custom Search