I've managed to get a ball rolling correctly in DP, the thing is, I need it to roll in the direction that the camera is facing.
I badly need help on this one, as i've been trying to figure it out for the last 2 days.
Heres the code for the rolling ball:
Rem Project: Sphere rotation
Rem Created: 15/01/2007 09:42:17
Rem ***** Main Source File *****
Set Display Mode 1024,768,32
Sync On : Sync Rate 60
Backdrop On : Color Backdrop 0
Autocam Off
Phy Start
`Global variables
Global cam_angy# as float
Global mmx# as float
`Create floor
Make Object Box 1,200,10,200
Position Object 1,0,0,0
Color Object 1,RGB(0,128,0)
Phy Make Rigid Body Static Mesh 1
`Create ball/sphere
Load Image "Stripe5.png",1
Make Object Sphere 2,8
Position Object 2,0,10,0
Texture Object 2,1
Phy Make Rigid Body Dynamic Sphere 2
`position camera around sphere (ready)
Position Camera 0,Object Position X(2),Object Position Y(2)+25,Object Position Z(2)
cam_angy# = 0
YRotate Camera cam_angy#
XRotate Camera 25
Move Camera 0,-60
Do
mmx# = MouseMoveX()
`Ball controls
If Keystate(17) `w key
phy add rigid body force 2,0.0,0.0,10,5
Endif
If Keystate(31) `s key
phy add rigid body force 2,0.0,0.0,-10,5
Endif
If Keystate(32) `d key
phy add rigid body force 2,10,0.0,0.0,5
Endif
If Keystate(30) `a key
phy add rigid body force 2,-10,0.0,0.0,5
Endif
`Apply linear and angular damping if no movement keys are pressed (i.e. w,a,s,d)
If Keystate(17) = 0 and Keystate(30) = 0 and Keystate(31) = 0 and Keystate(32) = 0
phy set rigid body linear damping 2,0.5
phy set rigid body Angular damping 2,0.5
Else
phy set rigid body linear damping 2,0.0
phy set rigid body Angular damping 2,0.0
Endif
`Position camera around sphere
Position Camera 0,Object Position X(2),Object Position Y(2)+25,Object Position Z(2)
If MouseClick() = 4 `Middle mouse button
cam_angy# = WrapValue(Camera Angle Y(0)-(mmx#/2))
YRotate Camera cam_angy#
XRotate Camera 25
Endif
If keystate(203) `left key
cam_angy# = WrapValue(Camera Angle Y(0)+1)
YRotate Camera cam_angy#
XRotate Camera 25
Endif
If keystate(205) `Right key
cam_angy# = WrapValue(Camera Angle Y(0)-1)
YRotate Camera cam_angy#
XRotate Camera 25
Endif
Move Camera 0,-60
`show FPS
Text 0,0,"FPS: "+STR$(Screen FPS())
`Update Dark Physics
Phy Update
`Sync
Sync
Loop
It uses an image called Stripe5.png, but you could change that to anything you like.
The controls are:
w,a,s,d - moves ball
Middle mouse button + mouse move or LEFT and RIGHT arrow keys.
I'd really appreciate anybody's help here. Thanks in advance.