|
width# (optional) - size along X; 2 (default) height# (optional) - height of the back, along Y; 2 (default) depth# (optional) - length of the slope, along Z; 2 (default) parent (optional) - parent entity for the new mesh; 0 for none (default) |
|
Creates a ramp-shaped wedge and returns its handle. The wedge fills the same box as CreateBox with the same sizes, centred on the origin. It is full height at the back (+Z) and slopes down to nothing at the front (-Z), with a flat base and back and triangular sides. Use it for blockout ramps, roof slopes, loading ramps and door wedges, and turn it with RotateEntity to face the slope another way. A tilted cube, the usual stand-in for a ramp, leaves a corner sticking out below the floor or above the landing. A wedge sits flat on the ground, and its top edge meets a platform of the same height exactly. The wedge is one surface with flat faces and crisp edges. Each face maps a texture from 0 to 1; on the slope U runs across and V down from the top edge. The wedge is a closed solid, so it works with the CSG commands. Automatic EntityPhysics gives it a convex hull, which for a wedge is exact, static or moving: balls roll down it and characters walk up it. PositionMesh, RotateMesh, ScaleMesh and FitMesh keep this, so a shape you have turned or resized with them keeps its collider. Editing its vertex positions or triangles, AddMesh or FlipMesh makes it an ordinary mesh again, and an explicit EntityPhysics shape, EntityBox, EntityRadius, EntityCapsule or EntityConvex always wins. Arguments are checked in release builds too: a size that is not a positive number stops the program with a runtime error naming the argument. See also: CreateBox, CreateCube, CreateFrustum, EntityPhysics. |
; CreateWedge Example
; -------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
; Automatic entity physics runs on the Box3D collision backend
SetCollisionBackend 1
Const SCENERY=1
Const PROPS=2
; The camera looks at the ramp from the side
camera=CreateCamera()
PositionEntity camera,-9,3,0
RotateEntity camera,10,-90,0
light=CreateLight()
RotateEntity light,45,-60,0
ground=CreateCube()
ScaleEntity ground,3,0.5,8
PositionEntity ground,0,-0.5,0
EntityColor ground,65,85,100
EntityType ground,SCENERY
EntityPhysics ground,0
; A ball to roll down the ramp; ScaleMesh keeps it a sphere for physics
ball=CreateSphere(16)
ScaleMesh ball,0.3,0.3,0.3
EntityColor ball,240,170,55
EntityType ball,PROPS
PositionEntity ball,0,3,2.2
EntityPhysics ball
Physics PROPS,SCENERY
ramp_steps=4
ramp=0
timer=CreateTimer(60)
While Not KeyDown(1)
; [ / ] change the height of the ramp
If KeyHit(26) And ramp_steps>1 Then
ramp_steps=ramp_steps-1
If ramp Then FreeEntity ramp
ramp=0
EndIf
If KeyHit(27) And ramp_steps<6 Then
ramp_steps=ramp_steps+1
If ramp Then FreeEntity ramp
ramp=0
EndIf
If ramp=0 Then
; Full height at the back (+Z), sloping down to nothing at the front
ramp_height#=ramp_steps*0.5
ramp=CreateWedge(2,ramp_height,5)
PositionEntity ramp,0,ramp_height/2,0
EntityColor ramp,200,120,80
EntityType ramp,SCENERY
; A static wedge gets an exact convex collider
EntityPhysics ramp,0
EndIf
; Space puts the ball at the top of the ramp
If KeyHit(57) Then
PositionEntity ball,0,ramp_height+0.5,2.2
ResetEntity ball
EndIf
; Arrow keys move the camera
If KeyDown(200) Then MoveEntity camera,0,0,0.1
If KeyDown(208) Then MoveEntity camera,0,0,-0.1
If KeyDown(203) Then TurnEntity camera,0,1,0
If KeyDown(205) Then TurnEntity camera,0,-1,0
UpdateWorld
RenderWorld
Text 0,0,"Arrow keys: move camera [ / ] : ramp height Space: roll a ball Esc: exit"
Text 0,20,"CreateWedge(2,"+ramp_height+",5)"
Text 0,40,"The back (+Z) is full height; the front meets the ground"
Flip
WaitTimer timer
Wend
End