Hi,
I don't know whether this is exactly what you need, but I once managed to create a bouncing ball using the "vec_bounce(...)" function. Check it out in the manual, maybe that's what you need. At least this works fine if the hit object is static. If the hit surface belongs to a moving object, the ball will get a sort of "spin" which affects its movement. For this, however, there is no predefined function. In my project I solved it like this:
VECTOR* ball_direction = {x = 0; y = 0; z = 0;}
VECTOR* ball_spin = {x = 0; y = 0; z = 0;}
var ball_speed;
function ball_bounce() // this is the event attached to the ball with enable_block and enable_entity set to ON
{
//... here's the bounce-code using vec_bounce, changing the ball_direction vector
vec_set(ball_spin, nullvector);
if (you == player)
{
ball_spin.x = (-0.5)*player_speed.x; //play with this value in order to increase/decrease strength of the spin-effect
ball_spin.y = 0;
ball_spin.z = 0;
}
}
...
action ball_action()
{
set(me, ENABLE_BLOCK|ENABLE_ENTITY);
my.event = ball_bounce;
ball_direction.x = 1;
ball_direction.y = 1;
ball_direction.z = 0; // initial movement of the ball
vec_normalize(ball_direction, ball_speed); // apply the ball_speed
while(1) // main loop of the action
{
//... particle effects and so on...
c_move(me, ball_direction, ball_spin, IGNORE_PASSABLE);
// reduce the spin value
if (ball_spin.x > 0)
{
ball_spin.x -= 0.01;
}
if (ball_spin.x < 0)
{
ball_spin.x += 0.01;
}
if ((ball_spin.x < 0.01) && (ball_spin.x > -0.01))
{
ball_spin.x = 0;
}
wait(1);
}
}
And that's it. Note: my only moving object was the player entity. Therefore in the ball_bounce function I only ask whether the ball has hit the player or not. Moreover, the player in my game may only move along the x-axis, so calculating the spin in here is rather simple and by no means representative for a complex movement in 3-dimensional space. Nevertheless, I hope this helps. Oh, and one last thing: the original code was written in c-script and I transfered it into lite-c now so there might be some synthax errors...
Greets,
Alan