PhysicsShapeCast
Jump to navigation
Jump to search
Tests collision ( like ray cast ) between two position having shape you provided. Remember to let world update before cast, just wait one frame.
Syntax
table physicsShapeCast(physics-shape theShape, float startX, float startY, float startZ, float endX, float endY, float endZ [ , float startRotationX, float startRotationY, float startRotationZ, float endRotationX, float endRotationY, float endRotationZ ] )
Required Arguments
- theShape: Primitive shape, supported shapes: "box", "sphere", "cone", "cylinder"
- startXYZ: start position.
- endXYZ: end position.
- startRotationXYZ: start rotation, by default 0,0,0.
- endRotationXYZ: end rotation, by default 0,0,0.
Returns
table with content:
- hit boolean - indicate does hit occurs.
- shapeposition {x,y,z} - position of shape in moment of contact.
- shaperotation {x,y,z} - rotation of shape in moment of contact.
- hitpoint {x,y,z} - contact point.
- hitnormal {x,y,z} - contact normal vector.
- shape physics-shape - contact shape.
- staticcollision physics-shape - contact static collision, can be false.
- rigidbody physics-rigid-body - contact rigid body, can be false.
Example
Creates giant random tetris
local function dropShapeAtPosition(shape, x,y,z) local result = physicsShapeCast(shape, x,y,z + 1000, x,y,z - 1000) if(result.hit)then local collision = physicsCreateStaticCollision(physics, shape) physicsSetProperties(collision, "position", result.shapeposition[1], result.shapeposition[2], result.shapeposition[3]) physicsSetProperties(collision, "rotation", result.shaperotation[1], result.shaperotation[2], result.shaperotation[3]) end end function tetris() setTimer(function() local box = physicsCreateShape(physics, "box", math.random() * 5 + 1, math.random() * 5 + 1, math.random() * 2 + 1) dropShapeAtPosition(box, math.random(60),math.random(60),0) end,0,1000) end tetris()
See Also
- physicsCreateWorld
- physicsDestroy
- physicsCreateShape
- physicsCreateShapeFromModel
- physicsCreateRigidBody
- physicsCreateStaticCollision
- physicsCreateConstraint
- physicsAddChildShape
- physicsRemoveChildShape
- physicsGetChildShapes
- physicsSetChildShapeOffsets
- physicsGetChildShapeOffsets
- physicsGetShapes
- physicsGetRigidBodies
- physicsGetStaticCollisions
- physicsGetConstraints
- physicsSetProperties
- physicsGetProperties
- physicsDrawDebug
- physicsSetDebugMode
- physicsBuildCollisionFromGTA
- physicsApplyVelocity
- physicsApplyVelocityForce
- physicsApplyAngularVelocity
- physicsApplyAngularVelocityForce
- physicsApplyDamping
- physicsRayCast
- physicsShapeCast
- physicsGetElementType
- physicsIsElement