EntityRadius entity,x_radius#[,y_radius#]

Parameters

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

Description

Sets the size of an entity's collision ellipsoid.

The ellipsoid is the shape an entity moves through the world as. Collision checking is always ellipsoid-to-something, so every source entity in a Collisions pair needs a radius - and so do destination entities in ellipsoid-to-ellipsoid pairs (method 1).

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.

See also: EntityBox, EntityType, Collisions, CountCollisions.

Example

; 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

Index