Skip to content

Common GameObject Functionality

nikki93 edited this page Sep 13, 2010 · 6 revisions

Functionality most objects provide. Every object may not have everything, these are only available where they make sense (‘applyCentralImpulse’ does not make sense for a ‘StaticBrush’).

Properties

type : ""
The type of the object. This tells the C++ code which type of GameObject it has to create. Usually you don’t have to set this yourself.

name : “noname”
The name of the object. Using a name allows you to refer to the object from anywhere. "" and “noname” are special names meaning, “the object doesn’t have a name”.

isBrush : ""
The presence of this property indicates that this object is a brush. There’s no value for it, it’s just either there, or not there. Again, this is a property you usually don’t have to set yourself.

script : ""
A string of Python code, which becomes the ‘script’ for the object. To listen for events, define a function with the respective name and arguments. Since it’s hard to write a script in one line, in Blender, you can write the script in the Blender text editor, and write ‘refText textname’ (textname being the name of the Text object in Blender) in the ‘script’ field to make things easier.

Python Events

init(self):
Called when the GameObject is first created. At this point, the other GameObjects may or may not have been created. If your code requires some other GameObject to exist, best use the ‘create(self):’ event. This event is also called when the GameObject is created due to deserialising (loading from a save file).

create(self):
Called after the entire level is loaded. This is not called when deserialising.

destroy(self):
Called when the GameObject is destroyed.

utick(self, elapsed):
Called every ‘tick’ (frame), when the game is not paused. ‘elapsed’ is the time elapsed (in seconds) since the last tick.

ptick(self, elapsed):
Called every tick, when the game is paused. ‘elapsed’ is the time elapsed (in seconds) since the last tick.

collide(self, other):
Called when a physical GameObject collides with another. ‘other’ is a handle to the other GameObject.

alarm(self, index):
Called when an alarm rings. ‘number’ is the index of the alarm. Alarms can be set by the ’setAlarm method described below.

Python Properties

(none)

Python Methods

getID()
Returns the ID of the GameObject.

getName()
Returns the name of the GameObject.

addFlag(flag)
Adds the given flag (a string) to the GameObject flags.

hasFlag(flag)
Returns whether the GameObject has the given flag.

removeFlag(flag)
Removes the given flag from the GameObject flags.

getFlags()
Returns a string containing all the flags the GameObject has delimited by ‘|’, starting and ending with ‘|’. For example, “|Bomb|Dangerous|”.

getProperty(name, index, default)
Gets the string value with the given index belonging to the given property, and if not found, returns the default value. For example, ‘light.getProperty(“colour”, 1, “0.5”)’ would return the green coefficient of the light’s colour (index starts from ‘0’), and “0.5” if the property wasn’t found.

setAlarm(time, index)
Sets the alarm with the given index to ring after the given time (in seconds).

getPosition()
Returns an Ngf.Vector3 describing the position of the GameObject.

setPosition(pos)
Sets the position to the given Ngf.Vector3.

translate(disp)
Translates the GameObject by the given displacement.

getOrientation()
Returns an Ngf.Quaternion describing the orientation of the GameObject.

applyForce(force, offset)
Applies the given force at the given offset from the origin.

applyCentralForce(force)
Applies the given force at the origin.

getTotalForce()
Returns the total force acting on the object.

applyTorque(torque)
Applies the given torque on the object.

applyTorueImpulse(impulse)
Changes the angular momentum by the given amount.

getTotalTorque()
Returns the total torque acting on the object.

applyImpulse(impulse, offset)
Applies an impulsive force (sudden change in momentum) at the given offset from the origin.

applyCentralImpulse(impulse)
Applies an impulsive force at the origin.

setLinearVelocity(velocity)
Sets the linear velocity to the given one.

getLinearVelocity()
Returns the Ngf.Vector3 describing the linear velocity of the object.

getVelocityInLocalPoint(offset)
Returns the velocity of a particle at the given offset from the origin.

setAngularVelocity(velocity)
Sets the angular velocity to the given one.

getAngularVelocity()
Returns the angular velocity of the object.

Clone this wiki locally