Class GameObject
java.lang.Object
net.risingworld.api.worldelements.GameObject
"Empty" base class for all custom elements. You can still use this class to set up parent/child hierarchies, and you
can also assign colliders to it (which may act as invisible barriers, interaction areas or triggers).
Example: Spawn GameObject and a child
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addChild
(GameObject child) void
addComponent
(String component) int
Gets the number of attached child objects on this object.Gets an unmodifiable list of all children of this object.Gets the collider that was assigned viasetCollider(net.risingworld.api.collider.Collider)
.int
getID()
Gets the unique ID of this object.int
getLayer()
Gets the layer that is assigned to this game object.Gets the local position of this object, relative to its parent.Gets the rotation of this object, relative to its parent.Gets the current local scale of this game object.Gets the current parent UI element, or null if this element has no parent.void
invokeComponentMethod
(String component, String method, Object... parameters) boolean
isActive()
Gets whether or not this object is currently active.boolean
boolean
Gets whether or not this game object is disposed.void
moveToLocalPosition
(float x, float y, float z, float speed) Smoothly moves this object to a target local position.void
moveToLocalPosition
(float x, float y, float z, float speed, Callback<Consumer<Vector3f>> callback) Smoothly moves this object to a target local position.void
moveToLocalPosition
(Vector3f position, float speed) Smoothly moves this object to a target local position.void
moveToLocalPosition
(Vector3f position, float speed, Callback<Consumer<Vector3f>> callback) Smoothly moves this object to a target local position.void
moveToLocalTransform
(Vector3f position, Quaternion rotation, float speed) Smoothly moves and rotates this object to a target local position and rotation.void
Removes all children from this element.void
removeChild
(GameObject child) Removes a child from this object.void
removeComponent
(String component) void
Removes this object from its parent.void
rotateToLocalRotation
(Quaternion rotation, float speed) Smoothly rotates this object to a target local rotation.void
setActive
(boolean set) Toggles the active state of this object.void
setCollider
(Collider collider) Assigns a collider to this game object.void
setColliderVisible
(boolean set) A debug method to visualize the collider of this game object.void
setComponentEnabled
(String component, boolean enabled) void
setComponentProperty
(String component, String property, Object value) Assigns a value to any component property via reflection.void
setLayer
(int layer) Sets theLayer
for this game object.void
setLocalPosition
(float x, float y, float z) Sets the position of this object, relative to its parent.void
setLocalPosition
(Vector3f position) Sets the position of this object, relative to its parent.void
setLocalRotation
(float pitch, float yaw, float roll) Sets the rotation of this object, relative to its parent.void
setLocalRotation
(Quaternion rotation) Sets the rotation of this object, relative to its parent.void
setLocalScale
(float x, float y, float z) Sets the local scale of this object, relative to its parent.void
setLocalScale
(Vector3f scale) Sets the local scale of this object, relative to its parent.
-
Constructor Details
-
GameObject
public GameObject() -
GameObject
public GameObject(int layer)
-
-
Method Details
-
getID
public int getID()Gets the unique ID of this object. Note that this ID is only valid during the session.- Returns:
- the unique ID of this object.
-
isDisposed
public boolean isDisposed()Gets whether or not this game object is disposed.- Returns:
- true if this game object is disposed, false if not.
-
setActive
public void setActive(boolean set) Toggles the active state of this object. Setting this to false will disable the object in the game scene, i.e it is no longer visible and no longer collides with the player or the world. This automatically affects all child elements as well.
By default, an object is set to active.- Parameters:
set
- true to set the object active, false to disable it.
-
isActive
public boolean isActive()Gets whether or not this object is currently active. Does not check the hierarchy recursively! If the parent of this element is not active, but childs are active, they are treated as non-active elements by the game, but this method would still return true.- Returns:
- true if this element is set to active, false if not.
-
setLayer
public void setLayer(int layer) Sets theLayer
for this game object.- Parameters:
layer
- the layer you want to set.- See Also:
-
getLayer
public int getLayer()Gets the layer that is assigned to this game object.- Returns:
- the layer.
- See Also:
-
setLocalPosition
Sets the position of this object, relative to its parent. If this object has no parent, this is the world position.- Parameters:
position
- a vector which holds the new position coordinates.
-
setLocalPosition
public void setLocalPosition(float x, float y, float z) Sets the position of this object, relative to its parent. If this object has no parent, this is the world position.- Parameters:
x
- the x position (horizontally).y
- the y position (vertically).z
- the z position (horizontally).
-
getLocalPosition
Gets the local position of this object, relative to its parent. If this object has no parent, this is the world position.- Returns:
- the local position, represented as a Vector3f.
-
setLocalRotation
Sets the rotation of this object, relative to its parent. If this object has no parent, this is the world rotation.- Parameters:
rotation
- the quaternion which represents the new rotation.
-
setLocalRotation
public void setLocalRotation(float pitch, float yaw, float roll) Sets the rotation of this object, relative to its parent. If this object has no parent, this is the world rotation.- Parameters:
pitch
- the pitch (rotation around X axis).yaw
- the yaw (rotation around Y axis, i.e heading).roll
-
-
getLocalRotation
Gets the rotation of this object, relative to its parent. If this object has no parent, this is the world rotation.- Returns:
- a quaternion which represents the current rotation.
-
setLocalScale
Sets the local scale of this object, relative to its parent. If this object has no parent, this is the world scale.- Parameters:
scale
- the new scale along the X, Y and Z axis.
-
setLocalScale
public void setLocalScale(float x, float y, float z) Sets the local scale of this object, relative to its parent. If this object has no parent, this is the world scale.- Parameters:
x
- the scale along the X axis.y
- the scale along the Y axis.z
- the scale along the Z axis.
-
getLocalScale
Gets the current local scale of this game object.- Returns:
- a Vector3f representing the local scale of the object (along the X, Y and Z axis).
-
moveToLocalPosition
Smoothly moves this object to a target local position.- Parameters:
position
- the new target position.speed
- the speed at which the object should move (units/blocks per second, e.g when setting it to 10, the object will move 10 units/blocks per second etc).- Example: Move game object 20 blocks upwards within 5 seconds
-
moveToLocalPosition
public void moveToLocalPosition(float x, float y, float z, float speed) Smoothly moves this object to a target local position.- Parameters:
x
- the target x position (horizontally).y
- the target y position (vertically).z
- the target z position (horizontally).speed
- the speed at which the object should move (units/blocks per second, e.g when setting it to 10, the object will move 10 units/blocks per second etc).
-
moveToLocalPosition
public void moveToLocalPosition(Vector3f position, float speed, Callback<Consumer<Vector3f>> callback) Smoothly moves this object to a target local position.- Parameters:
position
- the new target position.speed
- the speed at which the object should move (units/blocks per second, e.g when setting it to 10, the object will move 10 units/blocks per second etc).callback
- optional callback that gets invoked every tick (while the object is moving). This enables you to provide a new position through the Consumer object (seeConsumer.accept(java.lang.Object)
method).
-
moveToLocalPosition
public void moveToLocalPosition(float x, float y, float z, float speed, Callback<Consumer<Vector3f>> callback) Smoothly moves this object to a target local position.- Parameters:
x
- the target x position (horizontally).y
- the target y position (vertically).z
- the target z position (horizontally).speed
- the speed at which the object should move (units/blocks per second, e.g when setting it to 10, the object will move 10 units/blocks per second etc).callback
- optional callback that gets invoked every tick (while the object is moving). This enables you to provide a new position through the Consumer object (seeConsumer.accept(java.lang.Object)
method).
-
rotateToLocalRotation
Smoothly rotates this object to a target local rotation.- Parameters:
rotation
- the new target rotation.speed
- the speed at which the object should rotate.
-
moveToLocalTransform
Smoothly moves and rotates this object to a target local position and rotation.- Parameters:
position
- the new target position.rotation
- the new target rotation.speed
- the speed at which the object should move and rotate.
-
setCollider
Assigns a collider to this game object.- Parameters:
collider
- the new collider. Set to null to remove a collider.- Example: Add a box collider with size 2x2x2 to a game object
-
getCollider
Gets the collider that was assigned viasetCollider(net.risingworld.api.collider.Collider)
. Returns null if no collider was assigned.- Returns:
- the collider assigned to this game object, or null if no collider has been assigned yet.
-
setColliderVisible
public void setColliderVisible(boolean set) A debug method to visualize the collider of this game object. Only works if a collider is assigned.- Parameters:
set
- true to show a debug visualization of this game object, false to hide it.
-
isColliderVisible
public boolean isColliderVisible() -
addComponent
-
removeComponent
-
setComponentEnabled
-
setComponentProperty
Assigns a value to any component property via reflection.- Parameters:
component
- the name/type of the component (e.g "Animator" if you want to access an animator component).property
- the name of the property you want to change.value
- the new value you want to assign.
-
invokeComponentMethod
-
addChild
-
removeChild
Removes a child from this object. It will also be removed from the player world.- Parameters:
child
- the child object you want to remove.
-
removeAllChilds
public void removeAllChilds()Removes all children from this element. They will also be detached from the player UI. -
getParent
Gets the current parent UI element, or null if this element has no parent.- Returns:
- the parent element, or null if no parent is set.
-
removeFromParent
public void removeFromParent()Removes this object from its parent. Same as calling removeChild() on the parent object. -
getChilds
Gets an unmodifiable list of all children of this object.- Returns:
- a new, unmodifiable list containing all child objects.
-
getChildCount
public int getChildCount()Gets the number of attached child objects on this object.- Returns:
- the amount of children this object has. 0 if this object has no child objects.
-