To move an object forward based on it's angle you'd scale it's Look vector.
The Look vector is the forward direction the object is facing, same for Up and Right Vectors which are the up and right directions.
Here's how you'd work out these vectors: Google for more information
`all floats btw
pitch = angle x
yaw = angle y
roll = angle z
lookX = sin(roll) * sin(pitch) + cos(roll) * sin(yaw) * cos(pitch)
lookY = -cos(roll) * sin(pitch) + sin(roll) * sin(yaw) * cos(pitch)
lookZ = cos(yaw) * cos(pitch)
upX = -sin(roll) * cos(pitch) + cos(roll) * sin(yaw) * sin(pitch)
upY = cos(roll) * cos(pitch) + sin(roll) * sin(yaw) * sin(pitch)
upZ = cos(yaw) * sin(pitch)
rightX = cos(roll) * cos(yaw)
rightY = sin(roll) * cos(yaw)
rightZ = -sin(yaw)
Then you scale a position to move something, for example moving forward:
`scale the look vector by speed or the distance you want to move
moveX = lookX * speed
moveY = lookY * speed
moveZ = lookZ * speed
`then add to the position from where you want to move and that's all
x = posX + moveX
y = posY + moveY
z = posZ + moveZ
`or combine all in one
x = posX + (lookX * speed)
and etc...
Example of this by moving an object in front of another:
local pitch as float
local yaw as float
local roll as float
local lookX as float
local lookY as float
local lookZ as float
local x as float
local y as float
local z as float
sync on : sync rate 60
autocam off
position camera 0,0,-5
make object cube 1,2
make object cube 2,0.5
color object 2,rgb(255,0,0)
do
rotate object 1,wrapvalue(object angle x(1)+1),wrapvalue(object angle y(1)+1),0
pitch = object angle x(1)
yaw = object angle y(1)
roll = object angle z(1)
lookX = sin(roll) * sin(pitch) + cos(roll) * sin(yaw) * cos(pitch)
lookY = -cos(roll) * sin(pitch) + sin(roll) * sin(yaw) * cos(pitch)
lookZ = cos(yaw) * cos(pitch)
x = object position x(1) + (lookX * -1.25)
y = object position y(1) + (lookY * -1.25)
z = object position z(1) + (lookZ * -1.25)
rotate object 2, pitch, yaw, roll
position object 2, x, y, z
sync
loop
By combining all three it works exactly the same as offset limb.
Edit: Better example of moving:
` declare variables
local pitch as float
local yaw as float
local roll as float
local lookX as float
local lookY as float
local lookZ as float
local x as float
local y as float
local z as float
local ox as float
local oy as float
local oz as float
local speed as float
` setup screen
sync on : sync rate 60
` position camera
autocam off
position camera 0,0,-20
` setup objects
make object cube 1,2
make object cube 2,0.5
color object 2,rgb(255,0,0)
speed = 0.25
do
` if space key reset position and rotations
if spacekey()
x = 0 : y = 0 : z = 0
rotate object 1,rnd(359),rnd(359),rnd(359)
endif
` work out look vector
pitch = object angle x(1)
yaw = object angle y(1)
roll = object angle z(1)
lookX = sin(roll) * sin(pitch) + cos(roll) * sin(yaw) * cos(pitch)
lookY = -cos(roll) * sin(pitch) + sin(roll) * sin(yaw) * cos(pitch)
lookZ = cos(yaw) * cos(pitch)
` if return key, move along look vector
if returnkey()
inc x, (lookX * speed)
inc y, (lookY * speed)
inc z, (lookZ * speed)
endif
` finally update moved object
position object 1, x, y, z
` offset object infront of object 1
ox = object position x(1) + (lookX * 1.25)
oy = object position y(1) + (lookY * 1.25)
oz = object position z(1) + (lookZ * 1.25)
` update offset object
rotate object 2, pitch, yaw, roll
position object 2, ox, oy, oz
` debug
set cursor 0,0
print "Press Spacekey to reset object. Press Returnkey to move object"
sync
loop
"Get in the Van!" - Van B