Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog
Main Page About Help FAQ Special pages Log in

ShiVa Steering

From ShiVa Wiki




In this tutorial, we are going to learn how to add steering, flocking and a number of other automated movement behaviours to your Shiva game. We will be using a custom implementation inspired by the OpenSteer project. See links below for more information on the source material.


Source STE

Before we begin, please download the project ste containing all the code and assets we need for this tutorial.

Scene Setup

Steer pinkbox.jpg

We will use a large sensor box for the floor. You can initiate movement of the main character (Boid0) through this code in Main -> sendTapToScene:

local hHitObject, nHitDist, nHitSID = scene.getFirstHitSensorWithID ( hScene, nRayPntX, nRayPntY, nRayPntZ, nRayDirX, nRayDirY, nRayDirZ, 500, 0 )
-- -> sensor id = 0

If your floor shape is more complicated than this approximation, you might consider replacing it with colliders and collision raycasts (scene.getFirstHitColliderWithIDEx). Change the collider ID in the material to 1.

The id 1 in the material of the collider of the floor box is used to bring all the boids in the flock above the ground. Using a downwards ray from their position (ActorSteer -> update function), they can follow the floor height.

Now we have our scene set with the floor. Add colliders as limits and possibly objects that the boids should avoid, like so:

Steer scene.jpg


Ok, now take a look at the Main -> onInit event code: Here we are setting the behaviour for the first boid (the player) to "seeker".

object.setAIVariable ( hBoid,"ActorSteer","sState","seek" )

When the onMouseMove event of the Main AI is triggered, we are recording each movement of the mouse in a hashtable. Then, when the onEnterFrame event occurs, the function "seek" is called from Main AI, which sends an event to all Boids in the Scene with the "ActorSteer" AI, containing the new position of the player. "onUpdateNav" checks the behaviour to update the data.

Steer 3.jpg

Demo Video

Here is a little demo video of this project. All I did was add some more complex geometry and a little fine tuning:

Credits and Further Reading

Created by Juan "juaxix" Belón. Thanks to user @soybean for his steering behaviours tutorial

Link to the original forum thread

Want more? visit the OpenSteer Website

Alternative method on the forum

More forum goodness

Original C++ concept:

Retrieved from "http://www.shivaengine.com/developer/wiki/index.php?title=ShiVa_Steering"

This page has been accessed 939 times. This page was last modified on 26 May 2014, at 20:19.