Table of Contents
The example code is part of the FantasyDemo example game.
-
The example platform vehicle in FantasyDemo is the MovingPlatform. Its behaviour is to follow a path of User Data Objects of the type PlatformNode. The platform will wait at specific nodes and can randomly choose a direction when the path forks.
-
The PlatformNode editor script demonstrates changing in editor appearance based on property data as well as making path building easy and intuitive.
MovingPlatform is a Non-Player Character (NPC) entity that moves around the game scene along a specified path. The path is a connected graph of user data objects of type PlatformNode built in World Editor. MovingPlatform moves from one node to the next by applying and acceleration — this is achieved using the Entity.accelerateToPoint movement controller call on MovingPlatform's cell entity. The next node to which the MovingPlatform will traverse is randomly selected from those connected in the direction the platform it travelling. The editor script for the Patrol nodes ensures that no backwards or dual direction links exist so the platform will never double back on its self.
The MovingPlatform takes its path from a set of connected PlatformNode user data objects, which were implemented for building paths. For details see the document Content Tools Reference Guide's section World Editor → Useful notes → Patrol path editing with User Data Objects.
The path appears as a connected graph of nodes, with paths linking them together in a definite direction. From the path, the MovingPlatform can find traversable nodes to continue its movement. Each node also contains information such as how long the platform should wait at the node and how fast it should travel as it approaches the node. This node's data is also used to modify its appearance in World Editor. Below you will observe that one node is lager than the others. This is used to highlight nodes at which the MovingPlatform will stop.

Path of user data objects displayed in World Editor
The example MovingPlatform that follows a world builder defined path though the air. To move the platform the function Entity.accelerateToPoint() is used. This movement controller provides simple movement with smooth acceleration but makes no effort to avoid obstacles. It is entirely the world builder’s responsibility to ensure the platform does not fly through any walls.
Normally, we load models for various entities on the client using BigWorld.Model method. These loaded models, however are not added to the collision scene, i.e., instead of colliding with the entity/model, your player avatar (or NPC) will pass through the colliding entity.
In the case of our MovingPlatform, the player avatar will fall through the vehicle, instead of standing on top of it. We need to use BigWorld.PyModelObstacle to load the moving platform's model, in order to put the model in the collision scene on the client.
For example, in client/MovingPlatform.py file's enterWorld method:
self.model = BigWorld.PyModelObstacle( MovingPlatform.PLATFORM_MODEL, self.matrix, True )
Note
Any entity will become a vehicle when another entity boards it — there are no restrictions on which entity can become a vehicle.
Player-controlled avatar entity and server-controlled NPC entities use different mechanisms to board and alight from vehicles. A server-controlled NPC would need to explicitly use Entity.boardVehicle and Entity.alightVehicle, to board or alight from a vehicle.
Player-controlled avatar entities do not require explicit API calls to board or alight from a vehicle because the gravity calculations in the physics controller automatically detect if the player is standing on a vehicle. When player avatar moves away from the platform such that it is no longer underneath our player's feet, the entity physics controller will automatically alight them from the vehicle.
There are two requirements for this automatic boarding and alight mechanism to operate and they are as follows:
-
The player avatar must have its gravity attribute set in its physics object, as illustrated below:
BigWorld.player().physics.fall=1
-
The would-be vehicle entity must have its model vehicleID attribute set to itself — in our client/MovingPlatform.py's file enterWorld method:
self.model.vehicleID = self.id
Note
Server physics validation only works on client-controlled entities with topSpeed attribute greater than zero.
The server can perform limited physics validations on player-controlled avatar entities, apart from validate speed of player avatar, the server can also permit or disallow avatar getting on/off a vehicle. For details, see the document Server Programming Guide's section Proxies and Players → Physics Correction.
The onPassengerBoardAttempt and onPassengerAlightAttempt optional callback on vehicle entity are invoked when a player avatar boards or alights the vehicle. Returning True permits avatar's vehicle transition movement, otherwise the movement is disallowed, and avatar will be forced back to its earlier position in relation to the vehicle.
The current MovingPlatform implementation does not have any additional logic in the two callbacks, apart from a simple print statement.