Curved Motion Modelled as its Components
I use the following code each frame to control the movement of a ball. It works fine apart from I'm not sure how to apply a spin to the ball.
The Z component can be ignored becuase this will be more or less a constant.
Basically the ball is moving in side a box, along the Z axis toward the other side, when it reachs it it bounces and comes back, it continues doing this getting faster each time. On its way it can bounce off the other sides as it goes.
On the ends when it bounces back it is boncing off a moving surface, when this happens (I have the X,Y velocity of the moving surface) it will be given a spin based on how fast the surface was moving. I have tried giving the Acceleration the speed the surface was moving then giving the 2Acc (Rate of chnage of Acceleration) the negative speed but it doesn't seem to work :(. Does anyone have any idea?
Thanx.
VB Code:
'Adjust the Acceleration based on 2Acc...
Ball.XAcc = Ball.XAcc + Ball.X2Acc
Ball.YAcc = Ball.YAcc + Ball.Y2Acc
Ball.ZAcc = Ball.ZAcc + Ball.Z2Acc
'Adjust Velocity due to acceleration...
Ball.XVel = Ball.XVel + Ball.XAcc
Ball.YVel = Ball.YVel + Ball.YAcc
Ball.ZVel = Ball.ZVel + Ball.ZAcc
'Degrade the change in acceleration....
Ball.X2Acc = Ball.X2Acc * 0.999
Ball.Y2Acc = Ball.Y2Acc * 0.999
Ball.Z2Acc = Ball.Z2Acc * 0.999
If Abs(Ball.X2Acc) < 0.000001 Then Ball.X2Acc = 0
If Abs(Ball.Y2Acc) < 0.000001 Then Ball.Y2Acc = 0
If Abs(Ball.Z2Acc) < 0.000001 Then Ball.Z2Acc = 0
'Apply CofFriction...
Ball.XVel = Ball.XVel * 0.07
Ball.YVel = Ball.YVel * 0.07
Ball.ZVel = Ball.ZVel * 0.07
'Adjust the Position due to velocity...
Ball.XPos = Ball.XPos + Ball.XVel
Ball.YPos = Ball.YPos + Ball.YVel
Ball.ZPos = Ball.ZPos + Ball.ZVel