In my little code snippet below, the ball has starting coords and vectors for each axis, shouldn't there be some combination of functions which can simulate the ball rolling in the direction of its' vectors?
Please help if you can...
;**********************************
Function BallPhysics (Ball.Ball_Object)
If ball\y =< Ball\yMin# Then
Ball\y = Ball\yMin#
Ball\dy = -Ball\dy
Ball\dy = Ball\dy * Ball\elasticity
End If
If Ball\x =< Ball\xMin# Then
Ball\x = Ball\xMin#
Ball\dx = -Ball\dx
Ball\dx = Ball\dx * Ball\elasticity
End If
If Ball\x >= Ball\xMax# Then
Ball\x = Ball\xMax#
Ball\dx = -Ball\dx
Ball\dx = Ball\dx * Ball\elasticity
End If
If Ball\z =< Ball\zMin# Then
Ball\z = Ball\zMin#
Ball\dz = -Ball\dz
Ball\dz = Ball\dz * Ball\elasticity
End If
If Ball\z >= Ball\zMax# Then
Ball\z = Ball\zMax#
Ball\dz = -Ball\dz
Ball\dz = Ball\dz * Ball\elasticity
End If
If Ball\y >= Ball\yMin# Then
Ball\dy = Ball\dy + GRAVITY
End If
Ball\x = Ball\x + Ball\dx
Ball\z = Ball\z + Ball\dz
Ball\y = Ball\y + Ball\dy
Ball\dx = Ball\dx - (Ball\dx*Ball\friction)
Ball\dz = Ball\dz - (Ball\dz*Ball\friction)
;Move ball to new coords
PositionEntity Ball\Entity, Ball\x, Ball\y, Ball\z
;pitch#=VectorPitch(Ball\dx, Ball\dy, Ball\dz)
;yaw#=VectorYaw(Ball\dx, Ball\dy, Ball\dz)
;roll#=0
;Rotate mesh to give appearance of rolling
;RotateEntity Ball\Entity, pitch#, Yaw#, 0, 1
End Func
Please help if you can...
;**********************************
Function BallPhysics (Ball.Ball_Object)
If ball\y =< Ball\yMin# Then
Ball\y = Ball\yMin#
Ball\dy = -Ball\dy
Ball\dy = Ball\dy * Ball\elasticity
End If
If Ball\x =< Ball\xMin# Then
Ball\x = Ball\xMin#
Ball\dx = -Ball\dx
Ball\dx = Ball\dx * Ball\elasticity
End If
If Ball\x >= Ball\xMax# Then
Ball\x = Ball\xMax#
Ball\dx = -Ball\dx
Ball\dx = Ball\dx * Ball\elasticity
End If
If Ball\z =< Ball\zMin# Then
Ball\z = Ball\zMin#
Ball\dz = -Ball\dz
Ball\dz = Ball\dz * Ball\elasticity
End If
If Ball\z >= Ball\zMax# Then
Ball\z = Ball\zMax#
Ball\dz = -Ball\dz
Ball\dz = Ball\dz * Ball\elasticity
End If
If Ball\y >= Ball\yMin# Then
Ball\dy = Ball\dy + GRAVITY
End If
Ball\x = Ball\x + Ball\dx
Ball\z = Ball\z + Ball\dz
Ball\y = Ball\y + Ball\dy
Ball\dx = Ball\dx - (Ball\dx*Ball\friction)
Ball\dz = Ball\dz - (Ball\dz*Ball\friction)
;Move ball to new coords
PositionEntity Ball\Entity, Ball\x, Ball\y, Ball\z
;pitch#=VectorPitch(Ball\dx, Ball\dy, Ball\dz)
;yaw#=VectorYaw(Ball\dx, Ball\dy, Ball\dz)
;roll#=0
;Rotate mesh to give appearance of rolling
;RotateEntity Ball\Entity, pitch#, Yaw#, 0, 1
End Func