ResetEntity entity
Parameters
| entity - entity handle |
Description
|
Resets the collision state of an entity. The collision system works on movement: each UpdateWorld compares where an entity was with where it is now and resolves any collisions along the way. ResetEntity makes the entity's old position equal to its current one, so the next UpdateWorld sees no movement to check. Call it after teleporting an entity with PositionEntity - respawning a player, starting a new level, warping through a portal. Without the reset, the collision system treats the jump as one enormous movement and may slam the entity into everything between the two points, or stop it at the first obstacle. Note that EntityType also resets the entity's collision state when it assigns a type. See also: Collisions, EntityType, PositionEntity, UpdateWorld. |
Example
; ResetEntity Example ; ------------------- Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,0,-6 light=CreateLight() RotateEntity light,45,45,0 ; Spheres (type 1) collide with and slide off walls (type 2) Collisions 1,2,2,2 player=CreateSphere(16) ScaleEntity player,0.5,0.5,0.5 EntityRadius player,0.5 EntityType player,1 EntityColor player,0,255,100 wall=CreateCube() ScaleEntity wall,3,3,0.25 PositionEntity wall,0,0,3 EntityType wall,2 EntityColor wall,255,60,60 use_reset=1 While Not KeyDown(1) ; Arrow keys drive the sphere (up/down = towards/away from the wall) If KeyDown(203) Then MoveEntity player,-0.1,0,0 If KeyDown(205) Then MoveEntity player,0.1,0,0 If KeyDown(200) Then MoveEntity player,0,0,0.1 If KeyDown(208) Then MoveEntity player,0,0,-0.1 ; Space teleports the sphere to the far side of the wall If KeyHit(57) PositionEntity player,0,0,6 ; ResetEntity clears the collision state, so the jump is not treated ; as movement THROUGH the wall. Press R to turn it off and watch the ; collision system drag the sphere back to the wall instead. If use_reset Then ResetEntity player EndIf ; R toggles whether ResetEntity is used after the teleport If KeyHit(19) Then use_reset=1-use_reset UpdateWorld RenderWorld Text 0,0,"Arrows: drive Space: teleport past wall R: toggle ResetEntity Esc: exit" If use_reset Text 0,20,"ResetEntity ON - the teleport succeeds cleanly" Else Text 0,20,"ResetEntity OFF - the wall blocks the teleport" EndIf Flip Wend End
Index