|
|
Line 1: |
Line 1: |
− | The SPhysics class allows you to interact with the physics scene. See also [[Scripting/SRigidbody]].
| + | This page has moved to: https://docs.sine.space/v/scripting/client-scripting/scene/sphysics |
− | | + | |
− | | + | |
− | ==Members==
| + | |
− | {{ScriptFunction|SPhysicsHit|RayCast[]|(SVector origin, SVector normal, float distance);|Raycasts from origin along normal, distance meters - and returns the list of collided objects in distance order (closest first)|5=
| + | |
− | local trans=Space.Host.ExecutingObject<br>
| + | |
− | function Raycast()<br>
| + | |
− | local rays = Space.Physics.RayCast(trans.WorldPosition,trans.Forward,50)<br>
| + | |
− | if(rays~=nil and #rays>0) then<br>
| + | |
− | for i=0,#rays - 1 do<br>
| + | |
− | Space.Log(rays[i].Object.Name.." i = "..i)<br>
| + | |
− | end<br>
| + | |
− | end<br>
| + | |
− | end<br>
| + | |
− | trans.OnUpdate(Raycast)<br>
| + | |
− | ''Raycasts from origin in direction normal.''
| + | |
− | }}
| + | |
− | | + | |
− | {{ScriptFunction|SPhysicsHit|RayCastSingle|(SVector origin, SVector normal, float distance);|Raycasts from origin along normal, distance meters - and returns the list of collided objects in distance order (closest first)|5=
| + | |
− | local trans=Space.Host.ExecutingObject<br>
| + | |
− | function RaycastSingle()<br>
| + | |
− | local ray=Space.Physics.RayCastSingle(trans.WorldPosition,trans.Forward,50)<br>
| + | |
− | if(ray~=nil and ray.ContainsHit==true) then<br>
| + | |
− | Space.Log(ray.Object.Name)
| + | |
− | end<br>
| + | |
− | end<br>
| + | |
− | trans.OnUpdate(RaycastSingle)<br>
| + | |
− | ''Returns single raycast hit from origin in direction normal.''
| + | |
− | |6=<pre> --this script will make this object jump to wherever you right click
| + | |
− | --(Example: moving objects with right click )
| + | |
− | | + | |
− | thisGameObject = Space.Host.ExecutingObject
| + | |
− | | + | |
− | | + | |
− | OnUpdate = function()
| + | |
− | if Space.Input.GetMouseDown(1) then
| + | |
− | clickRay = Space.Camera.ScreenCoordinatesToRay(Space.Input.MousePosition)
| + | |
− | rayCastHit = Space.Physics.RayCastSingle(clickRay.Origin, clickRay.Direction, 50.0)
| + | |
− | thisGameObject.WorldPosition = rayCastHit.Position
| + | |
− | end
| + | |
− | end
| + | |
− | | + | |
− | thisGameObject.SubscribeToEvents()
| + | |
− | thisGameObject.OnUpdate(OnUpdate) </pre>}}
| + | |
− | | + | |
− | {{ScriptFunction|SPhysicsHit|SphereCast[]|(SVector origin, float radius, float distance);|Sweeps from origin in a spherical ray 'radius' wide, and returns the list of collided objects|5=
| + | |
− | local trans=Space.Host.ExecutingObject<br>
| + | |
− | function SphereRaycast()<br>
| + | |
− | local center=trans.WorldPosition + Vector.New(0.5,0.5,0.5)<br>
| + | |
− | local rays=Space.Physics.SphereCast(center,10,10,trans.Forward)<br>
| + | |
− | if rays~=nil and #rays>0 then<br>
| + | |
− | for i=0,#rays - 1 do<br>
| + | |
− | Space.Log(rays[i].Object.Name.." i = "..i)<br>
| + | |
− | end<br>
| + | |
− | end<br>
| + | |
− | end<br>
| + | |
− | trans.OnUpdate(SphereRaycast)<br>
| + | |
− | }}
| + | |
− | | + | |
− | {{ScriptFunction|SPhysicsHit|CapsuleCast[]|(SVector origin, SVector end, float radius, float distance);|Sweeps a capsule from origin to end, radius wide and returns the list of collided objects.|5=
| + | |
− | local trans=Space.Host.ExecutingObject<br>
| + | |
− | function CapsuleCast()<br>
| + | |
− | local startp=trans.WorldPosition<br>
| + | |
− | local endp=startp+trans.Up*10<br>
| + | |
− | local rays=Space.Physics.CapsuleCast(startp,endp,1,10,trans.Up)<br>
| + | |
− | if rays~=nil and #rays>0 then<br>
| + | |
− | for i=0,#rays - 1 do<br>
| + | |
− | Space.Log(rays[i].Object.Name.." i = "..i)<br>
| + | |
− | end<br>
| + | |
− | end<br>
| + | |
− | end<br>
| + | |
− | trans.OnUpdate(CapsuleCast)
| + | |
− | }}
| + | |
− | | + | |
− | {{ScriptFunction|SPhysicsHit|BoxCast[]|(SVector origin, SVector halfExtents, SVector direction, SQuaternion orientation, float distance);|Sweeps a box defined by origin+halfExtents along directiojn, distance meters with a orientation matching orientation - and returns the collisions in distance order.
| + | |
− | |5=local trans=Space.Host.ExecutingObject<br>
| + | |
− | function BoxCast()<br>
| + | |
− | local center=trans.WorldPosition + Vector.New(0.5,0.5,0.5)<br>
| + | |
− | local endp=local extents=Vector.new(2,2,2)<br>
| + | |
− | local rays=Space.Physics.BoxCast(center,extents,trans.Forward,Quaternion.Identity,2)<br>
| + | |
− | if rays~=nil and #rays>0 then<br>
| + | |
− | for i=0,#rays - 1 do<br>
| + | |
− | Space.Log(rays[i].Object.Name.." i = "..i)<br>
| + | |
− | end<br>
| + | |
− | end<br>
| + | |
− | end<br>
| + | |
− | trans.OnUpdate(BoxCast)
| + | |
− | }}
| + | |
− | | + | |
− | | + | |
− | | + | |
− | {{Scripting Navbox}}
| + | |