Skyline Lua API
Version 1.0 RC1
Lua Script Reference for Skyline Game Engine.
|
#include <LUA_API_Physics.h>
Public Member Functions | |
void | pause () |
Pauses the Physics system from updating meaning all physics object will stop moving, but also wont be collidable. No Arguments required. More... | |
void | resume () |
Resumes the physics which allows the update routines to work again as normal. No Arguments required. More... | |
int | addBody (int entityID, enum body_Type, int dynamic, int mass) |
Use this function to add a rigid body to the entity defined. More... | |
int | addTrigger (int entityID, int eventFlag) |
Use this function to add a Trigger volume to the defined entity. More... | |
void | setCollisionFlag (int bodyID, int eventFlag) |
Use this function to add any of the collision Event data to a scipt. Mainly used for microscripts to recieve collision event data. More... | |
int | addPlayerBody (int objID, float radius, float height, float heightOffset, int dynamic) |
Use this function to add a rigid body Player Capsule to the entity defined. More... | |
void | removeBody (int objID, int bodyID) |
REmoves an existing ridgid body. More... | |
int | getBodyID (int objID) |
Use this function to return the rigid body ID of an existing rigid body. More... | |
void | setActive (int bodyID, int state) |
Use this function to enable/disable an existing rigid body. More... | |
void | setSkinWidth (int bodyID, float width) |
Set the skin width of the physics object. More... | |
void | setMass (int bodyID, float mass) |
Use this function to set the mass of an existing rigid body. More... | |
float | getMass (int bodyID) |
Use this function to return the mass of an existing rigid body. More... | |
void | setBounce (int bodyID, float bounce) |
Use this function to set the bounce amount of an existing rigid body. More... | |
float | getBounce (int bodyID) |
Use this function to return the bounce of an existing rigid body. More... | |
void | setFriction (int bodyID, float friction) |
Use this function to set the friction amount of an existing rigid body. More... | |
float | getFriction (int bodyID) |
Use this function to return the friction of an existing rigid body. More... | |
void | setTerrainBounce (float bounce) |
Use this function to set the bounce amount of a terrain rigid body. More... | |
void | setTerrainFriction (float friction) |
Use this function to set the friction amount of a terrain rigid body. More... | |
void | setAngularVelocity (int bodyID, float x, float y, float z) |
Use this function to apply an angular velocity to the physics body. More... | |
float3 | getAngularVelocity (int bodyID) |
Use this function to get the angular velocity of the physics body in a float3. More... | |
void | setMaxAngularVelocity (int bodyID, x, y, z) |
Use this function to increase the maximum allowed rotational velocity. More... | |
void | setVelocity (int bodyID, x, y, z) |
Use this function to apply a vector velocity to an existing rigid body. More... | |
void | getVelocity (int bodyID) |
Use this function get the velocity of an existing rigid body. More... | |
float | getVelocityMagnitude (int bodyID) |
Use this function to get the speed of the physics body in (meters per second). More... | |
void | setLinearDamping (int bodyID, float linearDamping) |
Sets the linear damping coefficient of a physics body. More... | |
float | getLinearDamping (int bodyID) |
Gets the linear damping coefficient from a physics body. More... | |
void | setAngularDamping (int bodyID, float angularDamping) |
Sets the angular damping coefficient of a physics body. More... | |
float | getAngularDamping (int bodyID) |
Gets the angular damping coefficient from a physics body. More... | |
void | setImpulse (int bodyID, x, y, z) |
Use this function to apply a vector Impulse to an existing rigid body. More... | |
void | setImpulseAtPoint (int bodyID, float posX, float posY, float posZ, float impulseX, float impulseY, float impulseZ) |
Use this function to apply a vector Impulse to an existing rigid body from a position in world space. More... | |
void | setLocalImpulse (int bodyID, float impulseX, float impulseY, float impulseZ) |
Use this function to apply a local impulse to a physics body. More... | |
void | setLocalImpulseAtPoint (int bodyID, float posX, float posY, float posZ, float impulseX, float impulseY, float impulseZ) |
Use this function to apply a local impulse to a physics body from a local position. More... | |
void | setForce (int bodyID, x, y, z) |
Use this function to apply a vector Force to an existing rigid body. More... | |
void | setForceAtPoint (int bodyID, float posX, float posY, float posZ, float forceX, float forceY, float forceZ) |
Use this function to apply a vector Force to an existing rigid body from a position in world space. More... | |
void | setLocalForce (int bodyID, float forceX, float forceY, float forceZ) |
Use this function to apply a local force to a physics body. More... | |
void | setLocalForceAtPoint (int bodyID, float posX, float posY, float posZ, float forceX, float forceY, float forceZ) |
Use this function to apply a local force to a physics body from a local position. More... | |
void | setGravity (x, y, z) |
Sets the global gravity of the physic simulation. More... | |
void | setRotation (int bodyID, float w, float x, float y, float z) |
Sets the rotation of the physic body. More... | |
float4 | getRotation (int bodyID) |
Gets the rotation as a quaternion of the physics body specified. More... | |
void | setPosition (int bodyID, float x, float y, float z) |
Sets the position of the physic body. More... | |
float3 | getPosition (int bodyID) |
Gets the position of the physics body. More... | |
void | setBodyGravity (int bodyID, float x, float y, float z) |
**DEPRECIATED BULLET ** Sets the gravity of the specified rigidbody. More... | |
float3 | getGravity () |
Get the global gravity of the current physics simulation. More... | |
int | createRay () |
Creates a unique ray ready for ray casting. More... | |
float4 | rayFromPoint (int rayID, float x, float y, float z, float qw, float qx, float qy, float qz, float range) |
Creates a unique ray ready for ray casting. More... | |
float4 | rayFromPointByAxis (int rayID, float x, float y, float z, float rx, float ry, float rz, float range) |
Creates a unique ray ready for ray casting using physics. More... | |
void | rayDebugLines (int rayID, int state) |
Creates a unique ray ready for ray casting. More... | |
void | deleteRay (int rayID) |
Deletes the ray with the id rayID. More... | |
void | rayGetDistance (int rayID) |
Pass in the rayID from a raycast that has been used to get the distance of the ray. This distance is between the point of the ray start to the impacting position. More... | |
void | rayGetNormal (int rayID) |
Pass in the rayID from a raycast that has been used to get the normal of the surface the ray has intersected with The normal is the perpendicular angle to the face of the object intersected This is useful to raycast and find the angle a character is walking up or the angle a vehicle is driving up. More... | |
void | rayGetImpactPos (int rayID) |
Pass in the rayID from a raycast that has been used to get the impact position of the ray. When you raycast; if the ray hits any other physics object, then the position of that collision is passed back in this function. More... | |
void | setCollisionEnable_OnStart (int bodyID) |
Sets the contact report flag for collision start ie the first collision contact. More... | |
void | setCollisionEnable_OnStay (int bodyID) |
Sets the contact report flag for collision stay, ie while the objects intersect. More... | |
void | setCollisionEnable_OnEnd (int bodyID) |
Sets the contact report flag for collision end, ie as the object leaves the collision area. More... | |
void | setTriggerPosition (int bodyID, float x, float y, float z) |
Sets position of a spawned trigger using a float3. More... | |
void | setTriggerOrientation (int bodyID, float w, float x, float y, float z) |
Sets the rotation of a spawned trigger using a quaternion value. More... | |
String | getGameType (int objID) |
Gets the collision type from the physics object with a previously defined game type.Use this to quickly check for a specific type of objects when colliding. More... | |
void | setGameType (int objID, String gameType) |
Sets the collision type for the physics object. Use this to quickly check for a specific type of objects when colliding. More... | |
void | setGroupCollisionFlag (int groupFlag_1, int groupFlag_2, bool state) |
Enables the collision between two groups passed in the groupFlag arg. More... | |
void | assignGroupCollisionFlag (int bodyID, int groupFlag) |
Define which groups this object belongs to. More... | |
void | setSceneGravity (float x, float y, float z) |
Set the gravity of the physics scene. More... | |
void | move (int bodyID, float x, float y, float z) |
Moves a kinematic Rigidbody by a set amount. More... | |
void | rotate (int bodyID, float x, float y, float z, float w) |
Rotates a kinematic Rigidbody to a set orientation. More... | |
void | getContactData () |
Contafct Data. More... | |
void | getContactNumShapes () |
Get contact Shape Number. More... | |
float3 | getContactPoint (int shapeid) |
Get the Contact Point. More... | |
float | getContactForce (int shapeid) |
Get the force of the contact. More... | |
float3 | getContactNormal () |
Get contact normal. More... | |
int | getContactEntID () |
Get the ID of the object that made contact. More... | |
float4 | rayFromIDToID (int rayID, int sourceID, int targetID, float range, int optionalQueryFlag) |
Ray from ID to ID Fire a ranged ray between to objects source id and target id. Flags are so that you omit certian objects from being hit. More... | |
int | addBody (int objID, enum body_Type, int isDynamic, int mass, int isKinematic) |
Update to physics.addBody(..) if isKinematic = 1 then body uses kinemetic move, rotate Note isDynamic should also =1 as kinematic bodies are dynamic but do not respond to forces. More... | |
float3 | getStaticOffset (int bodyID) |
Get Static Offset the offset of the bodies position on the object. More... | |
All Physics functions can be accessed through the use of this class. Use as physics.function()
By adding a physics rigid body to an object you enable it to be controlled by the physics simulation. For more information on how these functions can be used please visit the User Manual - http://www.chi-ad.com/Skyline/SDN/
int Physics::addBody | ( | int | entityID, |
enum | body_Type, | ||
int | dynamic, | ||
int | mass | ||
) |
Use this function to add a rigid body to the entity defined.
entityID | : The ID of the Entity to add a rigid body to. |
body_Type | : the body type is represented by the numbers 0-5 |
dynamic | : pass 1 or 0 to make this body Dynamic or static. Once Static it will not be used in any dynamic physics calculations, but will still act as a collision surface. |
mass | : This is an optional parameter to the set the mass of a rigidbody. > 0 will set mass. If you leave the property out, then the default 10 is used |
Use the following enums for the body_Type argument or their corresponding number. 0 = enum.body_Cube()
1 = enum.body_Sphere()
2 = enum.body_Cylinder()
3 = enum.body_Capsule()
4 = enum.body_PlayerCapsule()
5 = enum.body_ConvexHull()
6 = enum.body_MeshHull()
By adding a rigid body to the object you can define how the object will be seen by the physics simulation. Some body types
are faster than others, try not to use the mesh body type unless really needed as this uses the most performance. If you never
need to move the object in game set dynamic = 0 to make the body a static collision object.
The following is a Small Example on how to use this function:
function spawnRidgidBody() x,y,z = entity.getPosition(obj); posx = x+math.random(-10,10); posy = y+math.random(-10,10); posz = z+math.random(-10,10); id = entity.spawn("Sphere_Med",posx,posy+10,posz,1,1,1); entity.addScript( id, "/TimedSelfRemoval.lua" ); bid = physics.addBody(id,enum.body_Sphere(),1); -- or if you want to specify a custom mass instead of the default 10 -- mass = 10000; --bid = physics.addBody(id,enum.body_Sphere(), 1, mass); end
int Physics::addBody | ( | int | objID, |
enum | body_Type, | ||
int | isDynamic, | ||
int | mass, | ||
int | isKinematic | ||
) |
Update to physics.addBody(..) if isKinematic = 1 then body uses kinemetic move, rotate Note isDynamic should also =1 as kinematic bodies are dynamic but do not respond to forces.
obj = 0; function bodyID = physics.addBody(int objID,enum body_Type, int isDynamic, int mass, int isKinematic); end
int Physics::addPlayerBody | ( | int | objID, |
float | radius, | ||
float | height, | ||
float | heightOffset, | ||
int | dynamic | ||
) |
Use this function to add a rigid body Player Capsule to the entity defined.
objID | : The ID of the Entity to add a rigid body to. |
radius | : The radius of the rigid body capsule |
height | : height of the body totalHeight = height + 2*Radius |
heightOffset | : the Y axis offset but will still act as a collision surface. |
dynamic | : pass 1 or 0 to make this body Dynamic or static. Once Static it will not be used in any dynamic physics calculations, but will still act as a collision surface. |
This special body is a player capsule is a full dynamic character controller that remains vertical, ie never fall over. It can be adjusted with
radius, height and y offset to match your character.
The following is a Small Example on how to use this function:
function onInit(objID) sky.lprint("\n Simple Physics Character Controller :: Active"); obj = objID; bodyID = physics.addPlayerBody(obj, radius, height, heightOffset, 1); physics.setMass(bodyID,2); physics.setBounce(bodyID,0); physics.setFriction(bodyID,1.0); end
int Physics::addTrigger | ( | int | entityID, |
int | eventFlag | ||
) |
Use this function to add a Trigger volume to the defined entity.
entityID | : The ID of the Entity to add a trigger volume to. |
eventFlag | : The bitwise flag to enable trigger contact. Trigger Event Flag examples: on_enter = 1, on_stay = 2, on_leave = 4 add the numbers to acess any combination. 3 = enter+stay |
By adding a Trigger Volume to the object you can effectivly change the objects shape into the volume to act
as the trigger. Any phyics object entering this volume will trigger an event.
The following is a Small Example on how to use this function:
function newTrigger() mesh = entity.spawn("Sphere",x,y+6,z,1,1,1); tID = physics.addTrigger(mesh,1); entity.addScript( mesh, "/testtrigger.lua" ); entity.setMaterialName(mesh, "Skyline_System_TriggerVolume"); sky.lprint("Trigger created with ID ="..tID); end
void Physics::assignGroupCollisionFlag | ( | int | bodyID, |
int | groupFlag | ||
) |
Define which groups this object belongs to.
bodyID | : The rigid body ID of the flag to set |
groupFlag | : Integer group flag value in the range 0 - 30 |
Use this to set any ridgid body's group flag
To enable/disable any group flag pair please see setGroupCollisionFlag(...)
The following is a Small Example on how to use this function:
obj = 0; function onInit(objID) sky.lprint("LUA: O2 Active!"); obj = objID; bodyID = physics.getBodyID(obj); physics.assignGroupCollisionFlag(bodyID,2); end
int Physics::createRay | ( | ) |
Creates a unique ray ready for ray casting.
The following is a Small Example on how to use this function:
function onInit(objID) obj = objID; rayID = physics.createRay(); end
void Physics::deleteRay | ( | int | rayID | ) |
Deletes the ray with the id rayID.
rayID | The int rayID of the ray |
The following is a Small Example on how to use this function:
function onStop() physics.deleteRay(rayID) end
float Physics::getAngularDamping | ( | int | bodyID | ) |
Gets the angular damping coefficient from a physics body.
bodyID | : The ID of the rigid body we want to get a angular damping from. |
function temp() currentAngularDamping = physics.getAngularDamping(bid); end
float3 Physics::getAngularVelocity | ( | int | bodyID | ) |
Use this function to get the angular velocity of the physics body in a float3.
bodyID | : The ID of the rigid body we want to get. |
The following is a Small Example on how to use this function:
function temp() x,y,z = physics.getAngularVelocity(bid); end
int Physics::getBodyID | ( | int | objID | ) |
Use this function to return the rigid body ID of an existing rigid body.
objID | : The ID of the entity we want to get the rigid body ID from. |
Returns the ID of a rigid body.
Also you cannot use this function in the scene scripts onInit() as any rigidbody is not yet created. Use the postInit() event instead.
The following is a Small Example on how to use this function:
function onInit() bodyID = physics.getBodyID(obj); end
float Physics::getBounce | ( | int | bodyID | ) |
Use this function to return the bounce of an existing rigid body.
bodyID | : The ID of the rigid body we want to set. |
Returns the bounce of the rigid body. see getBounce(bodyID)
The following is a Small Example on how to use this function:
function addRigidBody() bodyID = physics.addBody(id,enum.body_Sphere(),0); bounce = physics.getBounce(bodyID); end
void Physics::getContactData | ( | ) |
Contafct Data.
The following is a Small Example on how to use this function:
obj = 0; function onInit(objID) physics.getContactData(); end
int Physics::getContactEntID | ( | ) |
Get the ID of the object that made contact.
The following is a Small Example on how to use this function:
obj = 0; function contactID = physics.getContactEntID(); end
float Physics::getContactForce | ( | int | shapeid | ) |
Get the force of the contact.
Gets point the shape made contact
The following is a Small Example on how to use this function:
obj = 0; function contactforce = physics.getContactForce(shapeno); end
float3 Physics::getContactNormal | ( | ) |
Get contact normal.
The following is a Small Example on how to use this function:
obj = 0; function nx,ny,nz = physics.getContactNormal(); end
void Physics::getContactNumShapes | ( | ) |
Get contact Shape Number.
Gets the number of the shape that has made contact with the object.
The following is a Small Example on how to use this function:
obj = 0; function shapeno = physics.getContactNumShapes(); end
float3 Physics::getContactPoint | ( | int | shapeid | ) |
Get the Contact Point.
Gets point the shape made contact
The following is a Small Example on how to use this function:
obj = 0; function contx,conty,contz = physics.getContactPoint(shapeno); end
float Physics::getFriction | ( | int | bodyID | ) |
Use this function to return the friction of an existing rigid body.
bodyID | : The ID of the rigid body we want to set. |
Returns the friction of the rigid body. see getBounce(bodyID)
The following is a Small Example on how to use this function:
function addRigidBody() bodyID = physics.addBody(id,enum.body_Sphere(),0); bounce = physics.getFriction(bodyID); end
String Physics::getGameType | ( | int | objID | ) |
Gets the collision type from the physics object with a previously defined game type.Use this to quickly check for a specific type of objects when colliding.
objID | : The ID of the object ( not the bodyID )we want to set the collision type to. |
The following is a Small Example on how to use this function:
game_type= physics.getGameType(objID);
float3 Physics::getGravity | ( | ) |
Get the global gravity of the current physics simulation.
The following is a Small Example on how to use this function:
function onInit() x,y,z = physics.getGravity(); end
float Physics::getLinearDamping | ( | int | bodyID | ) |
Gets the linear damping coefficient from a physics body.
bodyID | : The ID of the rigid body we want to get a linear damping from. |
function temp() currentLinearDamping = physics.getLinearDamping(bid); end
float Physics::getMass | ( | int | bodyID | ) |
Use this function to return the mass of an existing rigid body.
bodyID | : The ID of the rigid body we want to set. |
Returns the mass of the rigid body. see setMass(bodyID,mass)
The following is a Small Example on how to use this function:
function addRigidBody() bodyID = physics.addBody(id,enum.body_Sphere(),0); mass = physics.getMass(bodyID); end
float3 Physics::getPosition | ( | int | bodyID | ) |
Gets the position of the physics body.
bodyID | : The ID of the rigid body we want to get. |
The following is a Small Example on how to use this function:
function onInit(objID) sky.lprint("LUA: Script Active!"); obj = objID; bodyID = physics.getBodyID(obj); x,y,z = physics.getPosition(bodyID); -- or pPos = newType.vec3(physics.getPosition(bodyID)); -- use as pPos.x, pPos.y, pPos.z end
float4 Physics::getRotation | ( | int | bodyID | ) |
Gets the rotation as a quaternion of the physics body specified.
bodyID | : The ID of the rigid body we want to get rotation from. |
The following is a Small Example on how to use this function:
function onInit(objID) obj = objID; bodyID = physics.getBodyID(obj); w,x,y,z = physics.getRotation(bodyID); -- or pRot = newType.vec4(physics.getRotation(bodyID)); end
float3 Physics::getStaticOffset | ( | int | bodyID | ) |
Get Static Offset the offset of the bodies position on the object.
obj = 0; function offsetx,offsety,offsetz = getStaticOffset(bodyID); end
void Physics::getVelocity | ( | int | bodyID | ) |
Use this function get the velocity of an existing rigid body.
bodyID | : The ID of the rigid body we want to return the value from. |
getVelocity(...) returns a vector representing the velocity of the body.
The following is a Small Example on how to use this function:
function setSpeed(speed) vx,vy,vz = physics.getVelocity(bodyID); physics.setVelocity(bodyID, speed ,vy, 0); end
float Physics::getVelocityMagnitude | ( | int | bodyID | ) |
Use this function to get the speed of the physics body in (meters per second).
bodyID | : The ID of the rigid body we want to get. |
Using the returned m/s value, you can convert to other unit forms such as mph, or kph with ease.
See the small example below
function temp() speedMeterPerSec = physics.getVelocityMagnitude(bid); speedKPH = speedMeterPerSec * 3.6f; speedMPH = speedKPH / 1.6; end
void Physics::move | ( | int | bodyID, |
float | x, | ||
float | y, | ||
float | z | ||
) |
Moves a kinematic Rigidbody by a set amount.
X | : Move the X Axis Position of the kinematic body |
Y | : Move the Y Axis Position of the kinematic body |
Z | : Move the Z Axis Position of the kinematic body |
The following is a Small Example on how to use this function:
obj = 0; function onInit(objID) obj = objID; physics.move(physics.getBodyID(obj), 0, 1, 0); end
void Physics::pause | ( | ) |
Pauses the Physics system from updating meaning all physics object will stop moving, but also wont be collidable. No Arguments required.
physics.pause();
void Physics::rayDebugLines | ( | int | rayID, |
int | state | ||
) |
Creates a unique ray ready for ray casting.
rayID | The int rayID of the ray |
state | 1-0 to enable/disable the debug lines for the ray |
Note: a ray must first exist by calling creatRay() before setting the debuglines.
The following is a Small Example on how to use this function:
function onKeyDown( key ) physics.rayDebugLines(rayID,1); end function onKeyUp( key ) physics.rayDebugLines(rayID,0 ); end
float4 Physics::rayFromIDToID | ( | int | rayID, |
int | sourceID, | ||
int | targetID, | ||
float | range, | ||
int | optionalQueryFlag | ||
) |
Ray from ID to ID Fire a ranged ray between to objects source id and target id. Flags are so that you omit certian objects from being hit.
obj = 0; function id,posX,poY,posZ = rayFromIDToID(rayID, sourceID, targetID, range, optionalQueryFlag); end
float4 Physics::rayFromPoint | ( | int | rayID, |
float | x, | ||
float | y, | ||
float | z, | ||
float | qw, | ||
float | qx, | ||
float | qy, | ||
float | qz, | ||
float | range | ||
) |
Creates a unique ray ready for ray casting.
x,y,z | : float values for the ray start position. |
qw,qx,qy,qz | : float values for the ray direction |
range | : float values for the ray distance, how far to cast the ray. |
The following is a Small Example on how to use this function:
function onInit(objID) sky.lprint("LUA: Script Active!"); obj = objID; rayID = physics.createRay(); end function onUpdate(td) range = 10; x,y,z = entity.getPosition(obj) qw,qx,qy,qz = entity.getWorldOrientation(obj) hitID,pox,posy,posz = physics.rayFromPoint(rayID, x,y+1,z,qw,qx,qy,qz,range); end
float4 Physics::rayFromPointByAxis | ( | int | rayID, |
float | x, | ||
float | y, | ||
float | z, | ||
float | rx, | ||
float | ry, | ||
float | rz, | ||
float | range | ||
) |
Creates a unique ray ready for ray casting using physics.
x,y,z | : float values for the ray start position. |
rx,ry,rz | : float values for the ray direction specified by axis: (1,0,0) x axis (0,1,0) y axis (0,0,1) z axis (-1,0,0) -x axis (0,-1,0) -y axis (0,0,-1) -z axis |
range | : float values for the ray distance, how far to cast the ray. |
The difference between this function and rayFromPoint is that is takes a float3
direction instead of float3 orientation.
The following is a Small Example on how to use this function:
function onInit(objID) sky.lprint("LUA: Script Active!"); obj = objID; rayID = physics.createRay(); end function onUpdate(td) range = 10; x,y,z = entity.getPosition(obj) rayDir = newType.vec3(0,-1,0); hitID,pox,posy,posz = physics.rayFromPointByAxis(rayID, x,y,z, rayDir.x, rayDir.y, rayDir.z, range); end
void Physics::rayGetDistance | ( | int | rayID | ) |
Pass in the rayID from a raycast that has been used to get the distance of the ray. This distance is between the point of the ray start to the impacting position.
rayID | The int rayID of the ray |
The following is a Small Example on how to use this function:
function onInit(objID) sky.lprint("LUA: Script Active!"); obj = objID; rayID = physics.createRay(); end function onUpdate(td) range = 10; x,y,z = entity.getPosition(obj) qw,qx,qy,qz = entity.getWorldOrientation(obj) hitID,pox,posy,posz = physics.rayFromPoint(rayID, x,y+1,z, qw,qx,qy,qz, range); distance = physics.rayGetDistance(rayID); end
void Physics::rayGetImpactPos | ( | int | rayID | ) |
Pass in the rayID from a raycast that has been used to get the impact position of the ray. When you raycast; if the ray hits any other physics object, then the position of that collision is passed back in this function.
Note: This is the impact position is world space
rayID | The int rayID of the ray |
The following is a Small Example on how to use this function:
function onInit(objID) sky.lprint("LUA: Script Active!"); obj = objID; rayID = physics.createRay(); end function onUpdate(td) range = 10; x,y,z = entity.getPosition(obj) qw,qx,qy,qz = entity.getWorldOrientation(obj) hitID,pox,posy,posz = physics.rayFromPoint(rayID, x,y+1,z,qw,qx,qy,qz, range); rayPos = newType.vec3(physics.rayGetImpactPos(rayID)); end
void Physics::rayGetNormal | ( | int | rayID | ) |
Pass in the rayID from a raycast that has been used to get the normal of the surface the ray has intersected with The normal is the perpendicular angle to the face of the object intersected This is useful to raycast and find the angle a character is walking up or the angle a vehicle is driving up.
Note: This is the normal is world space
rayID | The int rayID of the ray |
The following is a Small Example on how to use this function:
function onInit(objID) sky.lprint("LUA: Script Active!"); obj = objID; rayID = physics.createRay(); end function onUpdate(td) range = 10; x,y,z = entity.getPosition(obj) qw,qx,qy,qz = entity.getWorldOrientation(obj) hitID,pox,posy,posz = physics.rayFromPoint(rayID, x,y+1,z,qw,qx,qy,qz, range); normal = newType.vec3(physics.rayGetNormal(rayID)); end
void Physics::removeBody | ( | int | objID, |
int | bodyID | ||
) |
REmoves an existing ridgid body.
objID | : The ID of the Entity with the physics body. |
bodyID | : ID of body to remove |
physics.removeBody(int objID, int bodyID);
void Physics::resume | ( | ) |
Resumes the physics which allows the update routines to work again as normal. No Arguments required.
physics.resume();
void Physics::rotate | ( | int | bodyID, |
float | x, | ||
float | y, | ||
float | z, | ||
float | w | ||
) |
Rotates a kinematic Rigidbody to a set orientation.
X | : Rotation on the X axis for a quaternion. |
Y | : Rotation on the Y axis for a quaternion. |
Z | : Rotation on the Z axis for a quaternion. |
W | : Rotation on the W axis for a quaternion. |
The following is a Small Example on how to use this function:
obj = 0; function onInit(objID) obj = objID; physics.rotate(physics.getBodyID(obj), x, y, z, w); -- Note: The W is at the back instead of the front with this function. end
void Physics::setActive | ( | int | bodyID, |
int | state | ||
) |
Use this function to enable/disable an existing rigid body.
bodyID | : The ID of the rigid body we want to set. |
state | : A 1/0 value where state=1 is active |
To make an object go to sleep until it is needed helps with performance to do so call setActive(bodyID,0).
To re-awaken the object simply call setActive(bodyID,1).
Note if the body has been created with its dynamic variable set to 0 and is thus a static object any calls
to setActive(..) will have no effect.
The following is a Small Example on how to use this function:
function spawnRidgidBody() id = entity.spawn("Sphere_Med",0,5,0,1,1,1); bodyID = physics.addBody(id,enum.body_Sphere(),1); physics.setActive(bodyID,0);-- send to sleep physics.setActive(bodyID,1);-- wake up end
void Physics::setAngularDamping | ( | int | bodyID, |
float | angularDamping | ||
) |
Sets the angular damping coefficient of a physics body.
bodyID | : The ID of the rigid body we want to set a angular damping to. |
damping | : 0.0 means no damping; > 0 increases damping. Around 10.0 restricts movement a lot. The value to send for angular damping - Zero represents no damping. The angular damping coefficient must be a positive value. |
Giving a greater value than 0 will make it harder for the physics object to rotate.
function temp() physics.setAngularDamping(bid, 0.4); end
void Physics::setAngularVelocity | ( | int | bodyID, |
float | x, | ||
float | y, | ||
float | z | ||
) |
Use this function to apply an angular velocity to the physics body.
bodyID | : The ID of the rigid body we want to set. |
x | : A float value representing the X velocity to be applied to the rigidbody defined by bodyID. |
y | : A float value representing the Y velocity to be applied to the rigidbody defined by bodyID. |
z | : A float value representing the Z velocity to be applied to the rigidbody defined by bodyID. |
By calling setAngularVelocity(...) you can induce a constant rotation upon the physics body which
is slowed down by the angular damping of the object.
The following is a Small Example on how to use this function:
function spawnRidgidBody() x,y,z = entity.getPosition(obj); id = entity.spawn("Sphere_Med",x,y+10,z,1,1,1); bid = physics.addBody(id,0,1); physics.setAngularVelocity(bid,math.random(-3,3),math.random(20,30),math.random(-3,3)); end
void Physics::setBodyGravity | ( | int | bodyID, |
float | x, | ||
float | y, | ||
float | z | ||
) |
**DEPRECIATED BULLET ** Sets the gravity of the specified rigidbody.
bodyID | : The ID of the rigid body we want to use. |
x | : A float value representing the X Global Gravity. |
y | : A float value representing the Y Global Gravity. |
z | : A float value representing the Z Global Gravity. |
When you need to have more control over how gravity affects you rigid body you can call setBodyGravity(...) to
change how gravity affect the body. This does not change how gravity changes other object in the simulation, use
setBodyGravity(...) to effect every object.
The following is a Small Example on how to use this function:
function onInit(objID) sky.lprint("\n Simple Physics Character Controller :: Active"); obj = objID; bodyID = physics.addPlayerBody(obj, radius, height, heightOffset, 1); physics.setMass(bodyID,2); physics.setBounce(bodyID,0); physics.setFriction(bodyID,1.0); physics.setBodyGravity(bodyID,0,gravityOffset,0); end
void Physics::setBounce | ( | int | bodyID, |
float | bounce | ||
) |
Use this function to set the bounce amount of an existing rigid body.
bodyID | : The ID of the rigid body we want to set. |
bounce | : A float value representing the bounce of the body. |
The bounce of a rigid body affects how this object will perform on contact with another rigid body. The higher the value the
greater the rebound bounce will be, setBounce(0) to stop bouncing. Note: the surface this object has contacted must have a
bounce value greater than 0 for any bounce to occure.
The following is a Small Example on how to use this function:
function addRigidBody() bid = physics.addBody(id,enum.body_Sphere(),0); physics.setMass(bid,100); physics.setBounce(bid,0.2); physics.setFriction(bid,1); end
void Physics::setCollisionEnable_OnEnd | ( | int | bodyID | ) |
Sets the contact report flag for collision end, ie as the object leaves the collision area.
bodyID | : The ID of the rigid body we want to set. |
mass | : A float value representing the mass of the body. |
This command is required if you need to use collision events
The following is a Small Example on how to use this function:
function addRigidBody(mass,friction,bounce) bodyID = physics.addBody(id,enum.body_Sphere(),0); physics.setCollisionEnable_OnStart(bodyID) end
void Physics::setCollisionEnable_OnStart | ( | int | bodyID | ) |
Sets the contact report flag for collision start ie the first collision contact.
bodyID | : The ID of the rigid body we want to set. |
mass | : A float value representing the mass of the body. |
This command is required if you need to use collision events
The following is a Small Example on how to use this function:
function addRigidBody(mass,friction,bounce) bodyID = physics.addBody(id,enum.body_Sphere(),0); physics.setCollisionEnable_OnStart(bodyID) end
void Physics::setCollisionEnable_OnStay | ( | int | bodyID | ) |
Sets the contact report flag for collision stay, ie while the objects intersect.
bodyID | : The ID of the rigid body we want to set. |
mass | : A float value representing the mass of the body. |
This command is required if you need to use collision events
The following is a Small Example on how to use this function:
function addRigidBody(mass,friction,bounce) bodyID = physics.addBody(id,enum.body_Sphere(),0); physics.setCollisionEnable_OnStart(bodyID) end
void Physics::setCollisionFlag | ( | int | bodyID, |
int | eventFlag | ||
) |
Use this function to add any of the collision Event data to a scipt. Mainly used for microscripts to recieve collision event data.
body | : The ID of the Physics body you wish to add these flags to. |
eventFlag | : The bitwise flag to enable trigger contact. |
Flag examples: eventflag = 1 :: NX_NOTIFY_ON_START_TOUCH; eventflag = 2 :: NX_NOTIFY_ON_END_TOUCH; eventflag = 3 :: NX_NOTIFY_ON_START_TOUCH and NX_NOTIFY_ON_END_TOUCH; eventflag = 4 :: NX_NOTIFY_ON_TOUCH; eventflag = 7 :: NX_NOTIFY_ON_START_TOUCH and NX_NOTIFY_ON_END_TOUCH and NX_NOTIFY_ON_TOUCH;
The following is a Small Example on how to use this function:
function onInit() bid = physics.addBody(id,enum.body_Sphere(),0); physics.setCollisionFlag(bid, 6); -- this will use all 3 collision events (start, stay, stop) end
void Physics::setForce | ( | int | bodyID, |
x | , | ||
y | , | ||
z | |||
) |
Use this function to apply a vector Force to an existing rigid body.
bodyID | : The ID of the rigid body we want to set. |
x | : A float value representing the X Force to be applied to the rigidbody defined by bodyID. |
y | : A float value representing the Y Force to be applied to the rigidbody defined by bodyID. |
z | : A float value representing the Z Force to be applied to the rigidbody defined by bodyID. |
By calling setForce(...) an Force is applied to the specified rigidbody defined by bodyID.
A force is similar to setting velocity but differs in that the objects mass affects how much movement the force
imparts, but the speed remains constant unlike setImpulse(..).
The following is a Small Example on how to use this function:
function spawnRidgidBody() x,y,z = entity.getPosition(obj); id = entity.spawn("Sphere_Med",x,y+10,z,1,1,1); bodyID = physics.addBody(id,0,1); physics.setForce(bodyID,math.random(-3,3),math.random(20,30),math.random(-3,3)); end
void Physics::setForceAtPoint | ( | int | bodyID, |
float | posX, | ||
float | posY, | ||
float | posZ, | ||
float | forceX, | ||
float | forceY, | ||
float | forceZ | ||
) |
Use this function to apply a vector Force to an existing rigid body from a position in world space.
bodyID | : The ID of the rigid body we want to apply the force to. |
posx | : A float value representing the X Position to apply the force from. |
posy | : A float value representing the Y Position to apply the force from. |
posz | : A float value representing the Z Position to apply the force from. |
forcex | : A float value representing the X Force to be applied to the rigidbody defined by bodyID. |
forcey | : A float value representing the Y Force to be applied to the rigidbody defined by bodyID. |
forcez | : A float value representing the Z Force to be applied to the rigidbody defined by bodyID. |
By calling setForceAtPoint(...) an Force is applied to the specified rigidbody defined by bodyID.
A force is similar to setting velocity but differs in that the objects mass affects how much movement the force
imparts, but the speed remains constant unlike setImpulse(..).
The following is a Small Example on how to use this function:
function spawnRidgidBody() x,y,z = entity.getPosition(obj); id = entity.spawn("Sphere_Med",x,y+10,z,1,1,1); bodyID = physics.addBody(id,0,1); pos = newType.vec3(0,0,0); force = newType.vec3(math.random(-3,3),math.random(20,30),math.random(-3,3)); physics.setForceAtPoint(bodyID, pos.x, pos.y, pos.z, force.x,force.y,force.z); end
void Physics::setFriction | ( | int | bodyID, |
float | friction | ||
) |
Use this function to set the friction amount of an existing rigid body.
bodyID | : The ID of the rigid body we want to set. |
friction | : A float value representing the friction of the body. |
The friction of a rigid body affects how this object will slide on a surface. The higher the value the greater the
friction will be, setFriction(0.1) to slide on an ice like surface. Note: the surface this object has contacted must have a
friction value greater than 0 for any friction effects. Also to effectivly make an object roll the objects must have some
friction on both surfaces.
The following is a Small Example on how to use this function:
function addRigidBody() bid = physics.addBody(id,enum.body_Sphere(),0); physics.setMass(bid,100); physics.setBounce(bid,0.2); physics.setFriction(bid,1); end
void Physics::setGameType | ( | int | objID, |
String | gameType | ||
) |
Sets the collision type for the physics object. Use this to quickly check for a specific type of objects when colliding.
objID | : The ID of the object ( not the bodyID )we want to set the collision type to. |
gameType | : A string defining the collision type of this object. |
The following is a Small Example on how to use this function:
physics.setGameType(objID,"fish"); physics.setGameType(objID,"walls"); physics.setGameType(objID,"pickup"); game_type= physics.getGameType(bodyID);
void Physics::setGravity | ( | x | , |
y | , | ||
z | |||
) |
Sets the global gravity of the physic simulation.
x | : A float value representing the X Global Gravity. |
y | : A float value representing the Y Global Gravity. |
z | : A float value representing the Z Global Gravity. |
The following is a Small Example on how to use this function:
function onInit() physics.setGravity(0,-9.8,0); end
void Physics::setGroupCollisionFlag | ( | int | groupFlag_1, |
int | groupFlag_2, | ||
bool | state | ||
) |
Enables the collision between two groups passed in the groupFlag arg.
groupFlag_1 | : First group integer flag value in the range 0 - 30 |
groupFlag_2 | : Second group integer flag value in the range 0 - 30 |
state | : 1/0 seting this pair as Enabled/Disabled. |
In games there are many times when you require physics to only work with selected objects. For instance
if you have a physics bounds to prevent the player from going outside an area you will still need effects
and projectiles to pass through this bounds. To set the objects group flag please see assignGroupCollisionFlag(...)
The following is a Small Example on how to use this function:
physics.setGroupCollisionFlag(0,1,0); -- group 0 and 1 will not collide physics.setGroupCollisionFlag(1,2,1); -- group 1 and 2 will collide
void Physics::setImpulse | ( | int | bodyID, |
x | , | ||
y | , | ||
z | |||
) |
Use this function to apply a vector Impulse to an existing rigid body.
bodyID | : The ID of the rigid body we want to set. |
x | : A float value representing the X Impulse to be applied to the rigidbody defined by bodyID. |
y | : A float value representing the Y Impulse to be applied to the rigidbody defined by bodyID. |
z | : A float value representing the Z Impulse to be applied to the rigidbody defined by bodyID. |
By calling setImpulse(...) an Impulse is applied to the specified rigidbody defined by bodyID. An impulse is
an accumulative force on the moving body. By repeatedly applying impulse to a body it will move faster and faster.
An impulse is affected by mass, the greater the mass the higher the impulse must be to move it. This is unlike
velocity which provides the same speed increase regardless of the mass of the object.
The following is a Small Example on how to use this function:
function spawnRidgidBody() x,y,z = entity.getPosition(obj); id = entity.spawn("Sphere_Med",x,y+10,z,1,1,1); bodyID = physics.addBody(id,0,1); physics.setImpulse(bodyID,math.random(-3,3),math.random(20,30),math.random(-3,3)); end
void Physics::setImpulseAtPoint | ( | int | bodyID, |
float | posX, | ||
float | posY, | ||
float | posZ, | ||
float | impulseX, | ||
float | impulseY, | ||
float | impulseZ | ||
) |
Use this function to apply a vector Impulse to an existing rigid body from a position in world space.
bodyID | : The ID of the rigid body we want to apply the impulse to. |
posx | : A float value representing the X Position to apply the impulse from. |
posy | : A float value representing the Y Position to apply the impulse from. |
posz | : A float value representing the Z Position to apply the impulse from. |
impulsex | : A float value representing the X Impulse to be applied to the rigidbody defined by bodyID. |
impulsey | : A float value representing the Y Impulse to be applied to the rigidbody defined by bodyID. |
impulsez | : A float value representing the Z Impulse to be applied to the rigidbody defined by bodyID. |
By calling setImpulseAtPoint(...) an Impulse is applied to the specified rigidbody defined by bodyID. An impulse is
an accumulative force on the moving body. By repeatedly applying impulse to a body it will move faster and faster.
An impulse is affected by mass, the greater the mass the higher the impulse must be to move it. This is unlike
velocity which provides the same speed increase regardless of the mass of the object.
The following is a Small Example on how to use this function:
function spawnRidgidBody() x,y,z = entity.getPosition(obj); id = entity.spawn("Sphere_Med",x,y+10,z,1,1,1); bodyID = physics.addBody(id,0,1); pos = newType.vec3(0,0,0); impulse = newType.vec3(math.random(-3,3),math.random(20,30),math.random(-3,3)); physics.setImpulseAtPoint(bodyID, pos.x, pos.y, pos.z, impulse.x,impulse.y,impulse.z); end
void Physics::setLinearDamping | ( | int | bodyID, |
float | linearDamping | ||
) |
Sets the linear damping coefficient of a physics body.
bodyID | : The ID of the rigid body we want to set a linear damping to. |
damping | : The value to send for linear damping - Zero represents no damping. damping coefficient must be a positive value |
Giving a greater value than 0 will make it harder for the physics object to move through the scene.
function temp() physics.setLinearDamping(bid, 0.4); end
void Physics::setLocalForce | ( | int | bodyID, |
float | forceX, | ||
float | forceY, | ||
float | forceZ | ||
) |
Use this function to apply a local force to a physics body.
bodyID | : The ID of the rigid body we want to apply the force to. |
forcex | : A float value representing the X Local Force to be applied to the rigidbody defined by bodyID. |
forcey | : A float value representing the Y Local Force to be applied to the rigidbody defined by bodyID. |
forcez | : A float value representing the Z Local Force to be applied to the rigidbody defined by bodyID. |
By calling setLocalForce(...) an Force is applied to the specified rigidbody defined by bodyID.
A force is similar to setting velocity but differs in that the objects mass affects how much movement the force
imparts, but the speed remains constant unlike setImpulse(..).
The following is a Small Example on how to use this function:
function spawnRidgidBody() x,y,z = entity.getPosition(obj); id = entity.spawn("Sphere_Med",x,y+10,z,1,1,1); bodyID = physics.addBody(id,0,1); localForce = newType.vec3(0, 0, 1); physics.setLocalForce(bodyID, localForce.x, localForce.y, localForce.z); end
void Physics::setLocalForceAtPoint | ( | int | bodyID, |
float | posX, | ||
float | posY, | ||
float | posZ, | ||
float | forceX, | ||
float | forceY, | ||
float | forceZ | ||
) |
Use this function to apply a local force to a physics body from a local position.
bodyID | : The ID of the rigid body we want to apply the force to. |
posx | : A float value representing the X Position to apply the force from in local space. |
posy | : A float value representing the Y Position to apply the force from in local space. |
posz | : A float value representing the Z Position to apply the force from in local space. |
forcex | : A float value representing the X Local Force to be applied to the rigidbody defined by bodyID. |
forcey | : A float value representing the Y Local Force to be applied to the rigidbody defined by bodyID. |
forcez | : A float value representing the Z Local Force to be applied to the rigidbody defined by bodyID. |
By calling setLocalForceAtPoint(...) an Force is applied to the specified rigidbody defined by bodyID.
A force is similar to setting velocity but differs in that the objects mass affects how much movement the force
imparts, but the speed remains constant unlike setImpulse(..).
The following is a Small Example on how to use this function:
function spawnRidgidBody() x,y,z = entity.getPosition(obj); id = entity.spawn("Sphere_Med",x,y+10,z,1,1,1); bodyID = physics.addBody(id,0,1); pos = newType.vec3(1,0,-2); -- set 1 meter out on the x axis localForce = newType.vec3(1, 0, 0); -- this will set an force locally on the z axis of the model. physics.setLocalForceAtPoint(bodyID, pos.x, pos.y, pos.z, localForce.x, localForce.y, localForce.z); end
void Physics::setLocalImpulse | ( | int | bodyID, |
float | impulseX, | ||
float | impulseY, | ||
float | impulseZ | ||
) |
Use this function to apply a local impulse to a physics body.
bodyID | : The ID of the rigid body we want to apply the impulse to. |
impulsex | : A float value representing the X Local Impulse to be applied to the rigidbody defined by bodyID. |
impulsey | : A float value representing the Y Local Impulse to be applied to the rigidbody defined by bodyID. |
impulsez | : A float value representing the Z Local Impulse to be applied to the rigidbody defined by bodyID. |
By calling setLocalImpulse(...) an Impulse is applied to the specified rigidbody defined by bodyID. An impulse is
an accumulative force on the moving body. By repeatedly applying impulse to a body it will move faster and faster.
An impulse is affected by mass, the greater the mass the higher the impulse must be to move it. This is unlike
velocity which provides the same speed increase regardless of the mass of the object.
The following is a Small Example on how to use this function:
function spawnRidgidBody() x,y,z = entity.getPosition(obj); id = entity.spawn("Sphere_Med",x,y+10,z,1,1,1); bodyID = physics.addBody(id,0,1); localImpulse = newType.vec3(0, 0, 1); -- this will set an impulse locally on the z axis of the model. physics.setLocalImpulse(bodyID, localImpulse.x, localImpulse.y, localImpulse.z); end
void Physics::setLocalImpulseAtPoint | ( | int | bodyID, |
float | posX, | ||
float | posY, | ||
float | posZ, | ||
float | impulseX, | ||
float | impulseY, | ||
float | impulseZ | ||
) |
Use this function to apply a local impulse to a physics body from a local position.
bodyID | : The ID of the rigid body we want to apply the impulse to. |
posx | : A float value representing the X Position to apply the impulse from in local space. |
posy | : A float value representing the Y Position to apply the impulse from in local space. |
posz | : A float value representing the Z Position to apply the impulse from in local space. |
impulsex | : A float value representing the X Local Impulse to be applied to the rigidbody defined by bodyID. |
impulsey | : A float value representing the Y Local Impulse to be applied to the rigidbody defined by bodyID. |
impulsez | : A float value representing the Z Local Impulse to be applied to the rigidbody defined by bodyID. |
By calling setLocalImpulseAtPoint(...) an Impulse is applied to the specified rigidbody defined by bodyID. An impulse is
an accumulative force on the moving body. By repeatedly applying impulse to a body it will move faster and faster.
An impulse is affected by mass, the greater the mass the higher the impulse must be to move it. This is unlike
velocity which provides the same speed increase regardless of the mass of the object.
The following is a Small Example on how to use this function:
function spawnRidgidBody() x,y,z = entity.getPosition(obj); id = entity.spawn("Sphere_Med",x,y+10,z,1,1,1); bodyID = physics.addBody(id,0,1); pos = newType.vec3(1,0,-2); -- set 1 meter out on the x axis localImpulse = newType.vec3(1, 0, 0); -- this will set an impulse locally on the z axis of the model. physics.setLocalImpulseAtPoint(bodyID, pos.x, pos.y, pos.z, localImpulse.x, localImpulse.y, localImpulse.z); end
void Physics::setMass | ( | int | bodyID, |
float | mass | ||
) |
Use this function to set the mass of an existing rigid body.
bodyID | : The ID of the rigid body we want to set. |
mass | : A float value representing the mass of the body. |
The mass of a rigid body affects how it will behave in world, use setMass() to change the rigid bodies mass.
The following is a Small Example on how to use this function:
function addRigidBody(mass,friction,bounce) bodyID = physics.addBody(id,enum.body_Sphere(),0); physics.setMass(bodyID,mass); physics.setBounce(bodyID,bounce); physics.setFriction(bodyID,friction); end
void Physics::setMaxAngularVelocity | ( | int | bodyID, |
x | , | ||
y | , | ||
z | |||
) |
Use this function to increase the maximum allowed rotational velocity.
bodyID | : The ID of the rigid body we want to set. |
maxVelocity | : (7.0 - default) A float based value that sets the max angular velocity of a physics object. |
The following is a Small Example on how to use this function:
function spawnRidgidBody() x,y,z = entity.getPosition(obj); id = entity.spawn("Sphere_Med",x,y+10,z,1,1,1); bid = physics.addBody(id,0,1); physics.setMaxAngularVelocity(bid, 25); -- This makes a nice boulder rolling motion down a hill. (7.0 is default) end
void Physics::setPosition | ( | int | bodyID, |
float | x, | ||
float | y, | ||
float | z | ||
) |
Sets the position of the physic body.
bodyID | : The ID of the rigid body we want to set. |
x | : A float value representing the X position component. |
y | : A float value representing the Y position component. |
z | : A float value representing the Z position component. |
The following is a Small Example on how to use this function:
function onInit(objID) sky.lprint("LUA: Script Active!"); obj = objID; bodyID = physics.getBodyID(obj); physics.setPosition(bodyID, 10, 1, 0) end
void Physics::setRotation | ( | int | bodyID, |
float | w, | ||
float | x, | ||
float | y, | ||
float | z | ||
) |
Sets the rotation of the physic body.
bodyID | : The ID of the rigid body we want to set. |
w | : A float value representing the W rotation component. |
x | : A float value representing the X rotation component. |
y | : A float value representing the Y rotation component. |
z | : A float value representing the Z rotation component. |
The following is a Small Example on how to use this function:
function onInit(objID) sky.lprint("LUA: Script Active!"); obj = objID; bodyID = physics.getBodyID(obj); physics.setRotation(bodyID,w,x,y,z); end
void Physics::setSceneGravity | ( | float | x, |
float | y, | ||
float | z | ||
) |
Set the gravity of the physics scene.
X | : the X axis value to set for gravity. |
Y | : the Y axis value to set for gravity. |
Z | : the Z axis value to set for gravity. |
This is best to use in the scene scripts onInit, so it is set up before
any rigidbody is created.
The following is a Small Example on how to use this function:
obj = 0; function onInit(objID) sky.lprint("LUA: O2 Active!"); obj = objID; physics.setSceneGravity(0,-9.81,0); end
void Physics::setSkinWidth | ( | int | bodyID, |
float | width | ||
) |
Set the skin width of the physics object.
bodyID | : The ID of the rigid body we want to set. |
width | : the width of the physics object to penetrate. |
The skin width is how far the object has to penetrate another physics object before collision occurs. lol :P Default is 0.01
The following is a Small Example on how to use this function:
function addRigidBody(mass,friction,bounce) bodyID = physics.addBody(id,enum.body_Sphere(),0); physics.setMass(bodyID,mass); physics.setBounce(bodyID,bounce); physics.setFriction(bodyID,friction); end
void Physics::setTerrainBounce | ( | float | bounce | ) |
Use this function to set the bounce amount of a terrain rigid body.
bounce | : A float value representing the bounce amount of the rigid body. |
The bounce of a rigid body affects how this object will perform on contact with another rigid body. The higher the value the
greater the rebound bounce will be, setBounce(0) to stop bouncing. Note: for objects to bounce on the terrain the command
setTerrainBounce(value) must pass a value greater than 0.
The following is a Small Example on how to use this function:
function onInit(objID) sky.lprint("\n Setting Terrain Bounce Amount!"); obj = objID; physics.setTerrainBounce(1); end
void Physics::setTerrainFriction | ( | float | friction | ) |
Use this function to set the friction amount of a terrain rigid body.
friction | : A float value representing the friction of the body. |
The friction of a rigid body affects how object will slide on the terrain. The higher the value the greater the
friction will be.
The following is a Small Example on how to use this function:
function onInit(objID) sky.lprint("\n Setting Terrain Bounce Amount!"); obj = objID; physics.setTerrainFriction(1); end
void Physics::setTriggerOrientation | ( | int | bodyID, |
float | w, | ||
float | x, | ||
float | y, | ||
float | z | ||
) |
Sets the rotation of a spawned trigger using a quaternion value.
bodyID | : The ID of the rigid body/trigger body we want to set. |
w | : W Axis value to be set to the trigger. |
x | : X Axis value to be set to the trigger. |
y | : Y Axis value to be set to the trigger. |
z | : Z Axis value to be set to the trigger. |
The following is a Small Example on how to use this function:
function onKeyDown( key ) if(key == "t")then entity.yaw(obj, 10, 0); entOW,entOX,entOY,entOZ = entity.getWorldOrientation(obj); physics.setTriggerOrientation(entOW,entOX,entOY,entOZ); end end
void Physics::setTriggerPosition | ( | int | bodyID, |
float | x, | ||
float | y, | ||
float | z | ||
) |
Sets position of a spawned trigger using a float3.
bodyID | : The ID of the rigid body/trigger body we want to set. |
x | : X Axis value to be set to the trigger. |
y | : Y Axis value to be set to the trigger. |
z | : Z Axis value to be set to the trigger. |
The following is a Small Example on how to use this function:
function onKeyDown( key ) if(key == "t")then x = 0; y = 0.5; z = 10; physics.setTriggerPosition(triggerBodyID, x,y,z ); end end
void Physics::setVelocity | ( | int | bodyID, |
x | , | ||
y | , | ||
z | |||
) |
Use this function to apply a vector velocity to an existing rigid body.
bodyID | : The ID of the rigid body we want to set. |
x | : A float value representing the X velocity to be applied to the rigidbody defined by bodyID. |
y | : A float value representing the Y velocity to be applied to the rigidbody defined by bodyID. |
z | : A float value representing the Z velocity to be applied to the rigidbody defined by bodyID. |
By calling setVelocity(...) a velocity is applied to the specified rigidbody defined by bodyID. This is a linear
force only applied while calling this command, once setVelocity(...) has been called the object will slowly reduce
in movement based upon the gravity and mass of the object.Repeadedly applying velocity to a body will keep the body
moving at a constant speed unlike impuse which when applyied increases speed.
To use velocity for movement gives control over the speed of the object.
The following is a Small Example on how to use this function:
function spawnRidgidBody() x,y,z = entity.getPosition(obj); id = entity.spawn("Sphere_Med",x,y+10,z,1,1,1); bid = physics.addBody(id,0,1); physics.setVelocity(bid,math.random(-3,3),math.random(20,30),math.random(-3,3)); end