Blitz3D+ Command Reference

MoveEntity entity,x#,y#,z#

Parameters

entity - entity handle

x# - x amount that entity will be moved by
y# - y amount that entity will be moved by
z# - z amount that entity will be moved by

Description

Moves an entity relative to its current position and orientation - along its own local axes.

An entity moves in whatever direction it is facing: MoveEntity entity,0,0,1 always moves it one unit forward along its own z axis, whatever way it is turned. For an upright game character, a z amount moves it forward or backward, an x amount strafes, and a y amount moves it up or down relative to its own tilt. MoveEntity plus TurnEntity is all a basic driving or first-person controller needs.

This is one of three ways to change position, and picking the right one matters:

MoveEntity - moves along the entity's own local axes (direction depends on which way it faces).
TranslateEntity - moves along the world axes, ignoring the entity's orientation (jumping and gravity).
PositionEntity - jumps the entity to an absolute position instead of shifting it.

See also: TranslateEntity, PositionEntity, TurnEntity, PositionMesh.

Example

; MoveEntity Example
; ------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

SeedRnd MilliSecs()

camera=CreateCamera()
PositionEntity camera,0,0,-10

light=CreateLight()
RotateEntity light,45,45,0

; A ship we can fly around
ship=CreateCone(16)
EntityColor ship,0,200,255

While Not KeyDown(1)

    ; Reset movement values each frame - otherwise the ship would never stop
    x#=0
    y#=0
    z#=0

    ; Cursor keys and A/Z set this frame's movement
    If KeyDown(203) Then x=-0.1
    If KeyDown(205) Then x=0.1
    If KeyDown(208) Then y=-0.1
    If KeyDown(200) Then y=0.1
    If KeyDown(44) Then z=-0.1
    If KeyDown(30) Then z=0.1

    ; MoveEntity moves along the ship's own LOCAL axes: z is always "forward,
    ; wherever the ship is pointing". Compare TranslateEntity (world axes)
    ; and PositionEntity (absolute coordinates).
    MoveEntity ship,x,y,z

    ; Space rotates the ship randomly - the same keys then move it in NEW directions
    If KeyHit(57) Then RotateEntity ship,Rnd(0,360),Rnd(0,360),Rnd(0,360)

    RenderWorld

    Text 0,0,"Cursors/A/Z: move   Space: rotate randomly   Esc: exit"
    Text 0,20,"MoveEntity ship,"+x+","+y+","+z+"   (local axes)"

    Flip

Wend

End

Index