|
entity - entity handle x_radius# - radius of the entity's collision ellipsoid on the x and z axes y_radius# (optional) - separate radius for the y axis; 0 (default) means use x_radius# there too, giving a sphere |
|
Sets the size of an entity's collision ellipsoid. With the legacy backend, the ellipsoid is the shape an entity moves through the world as, so every source entity in a Collisions pair needs a radius. Method 1 also uses EntityRadius on its destination. With just x_radius# you get a sphere - right for balls, projectiles and most pickups. Adding a y_radius# stretches or squashes it vertically: a standing character suits something like EntityRadius player,0.5,1 - half a unit wide and deep, a full unit tall - so it can brush past furniture yet not sink into the floor. The z radius always matches the x radius. The radius is centred on the entity's origin. If a model's origin sits at its feet, position the entity (or its mesh) so the ellipsoid actually wraps the body rather than the ground below it. In Box3D classic-collision mode, equal radii cook a sphere and unequal radii cook a deterministic convex approximation of the vertical ellipsoid. World scale is applied when the hidden shape is built. Calling EntityRadius selects it as the source shape again after EntityCapsule or EntityConvex. Method 1 uses this radius on the destination unless its active definition is EntityCapsule, in which case Box3D uses that capsule instead. See also: EntityCapsule, EntityConvex, EntityBox, EntityType, Collisions, CountCollisions. |
; EntityRadius Example
; --------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
; Collision type ids
type_player=1
type_scenery=2
; NOTE: fixed overhead camera - the arrow keys steer the PLAYER, not the camera
camera=CreateCamera()
PositionEntity camera,0,13,-13
RotateEntity camera,45,0,0
light=CreateLight()
RotateEntity light,60,30,0
floor=CreatePlane()
EntityColor floor,70,110,70
; The player ball - the collision source whose radius we will change
player=CreateSphere()
EntityColor player,220,60,60
PositionEntity player,0,1,0
EntityType player,type_player
; A wall with a 2-unit doorway in the middle
wallL=CreateCube()
ScaleEntity wallL,2,1.2,1.2
PositionEntity wallL,-3,1.2,4
EntityColor wallL,150,150,160
EntityType wallL,type_scenery
wallR=CreateCube()
ScaleEntity wallR,2,1.2,1.2
PositionEntity wallR,3,1.2,4
EntityColor wallR,150,150,160
EntityType wallR,type_scenery
; Ellipsoid-to-polygon collisions with a sliding response
Collisions type_player,type_scenery,2,2
radius#=1.4
While Not KeyDown(1)
; Arrow keys steer the player ball
If KeyDown(200) Then MoveEntity player,0,0,0.1
If KeyDown(208) Then MoveEntity player,0,0,-0.1
If KeyDown(203) Then MoveEntity player,-0.1,0,0
If KeyDown(205) Then MoveEntity player,0.1,0,0
; [ and ] shrink or grow the collision radius
If KeyDown(26) And radius>0.3 Then radius=radius-0.02
If KeyDown(27) And radius<2 Then radius=radius+0.02
; The star of the show: set the ball's collision ellipsoid radius...
EntityRadius player,radius
; ...and scale the mesh to match, so what you see is what collides
ScaleEntity player,radius,radius,radius
; Keep the ball resting on the floor whatever its size
PositionEntity player,EntityX(player),radius,EntityZ(player)
; UpdateWorld performs the collision checks and the slide response
UpdateWorld
RenderWorld
Text 0,0,"Arrow keys: drive the ball [ / ] : change radius Esc: exit"
Text 0,20,"EntityRadius player,"+radius
Text 0,40,"The doorway is 2 units wide - shrink the radius below 1.0 to fit through"
Flip
Wend
End