bw logo

Chapter 3. Boarding and Alighting Vehicles

Boarding and alighting changes whether and entity's position is known relative to the world or relative to another entity such as a vehicle. When one entity boards another, it moves with the vehicle that it has boarded. This is most useful for vehicles where the entities are able to move around, such as the deck of a ship, but can also be useful when implementing vehicles where the avatar sits in a specific seat.

3.1. Functions

3.1.1. Entity.boardVehicle()

Boarding a vehicle makes the entity its passenger, and subject to its movements. Which vehicle the entity has boarded can be found through the entity's vehicle property, available on both the client and cell.

def requestBoardVehicle( self, sourceVehicleID ):
    vehicle = BigWorld.entities[ sourceVehicleID ]
    self.boardVehicle( sourceVehicleID )
    vehicle.passengerBoarded( self.id )

cell/Avatar.py

The vehicleID parameter is the entity ID of the vehicle that you are boarding (it cannot be None or 0).

This function changes the space of the entity to that of the vehicle, and sets the entity's vehicle property.

3.1.2. Entity.alightVehicle()

Having an entity alight from its vehicle makes its movement relative to the world.

def requestAlightVehicle( self, sourceVehicleID ):
    vehicle = BigWorld.entities[ sourceVehicleID ]
    if self.vehicle != None:
        self.alightVehicle()
    vehicle.passengerAlighted( self.id )

cell/Avatar.py

This function changes the space of the entity from that of the vehicle to that of the world.

It also sets the entity's vehicle property to None. Do not call this function if the entity is not aboard a vehicle.

Note

Both boardVehicle() and alightVehicle() must be used only from within member functions of the entity's cell. This is because they require the real entity, not a ghost of an entity that is in reality in a different cell.

3.2. Apply gravity and moving platforms

It is important to remember to disable falling when using these functions.

Falling objects automatically board and alight based on whether they are standing on the world, in mid-air, or are standing on a PyModelObstacle marked with a vehicleID. This mechanism will override whatever value you set, therefore the need to disable falling.

self.pilotAvatar.physics.fall = False

client/Ripper.py

3.3. Player vehicle

To become the player, the vehicle requires a player specialisation of the vehicle. The type of the vehicle is changed dynamically to and from its player variation.

import BigWorld

class Ripper( BigWorld.Entity ):
    def __init__( self ):
        BigWorld.Entity.__init__( self )

    def enterWorld( self ):
        pass

    def leaveWorld( self ):
        pass

class PlayerRipper( Ripper ):
    def onBecomePlayer( self ):
        pass

    def onBecomeNonPlayer( self ):
        pass

    def handleKeyEvent( self, isDown, key, mods ):
        return True

Outline of client/Ripper.py