Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (bdgogo), 1,447 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19056 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Bouncing? #268479
05/29/09 14:03
05/29/09 14:03
Joined: Mar 2005
Posts: 564
/www/europe/ germany/index.php
TSG_Torsten Offline OP

User
TSG_Torsten  Offline OP

User

Joined: Mar 2005
Posts: 564
/www/europe/ germany/index.php
Hi all,

I'm trying to make a simple bouncing ball. Well, I use c_move to let it move, but I run into problems by geting it physically correctly rebounding from other entities in dependences of the current movement and the hitten surface-alignment.

Could anybody give me a pseudo-code how to do this?

Thanks & Regards
TSGames

Re: Bouncing? [Re: TSG_Torsten] #268818
05/31/09 09:53
05/31/09 09:53
Joined: Oct 2007
Posts: 306
Austria
A
Alan Offline
Senior Member
Alan  Offline
Senior Member
A

Joined: Oct 2007
Posts: 306
Austria
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:

Code:

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

Re: Bouncing? [Re: Alan] #269970
06/05/09 11:18
06/05/09 11:18
Joined: Mar 2005
Posts: 564
/www/europe/ germany/index.php
TSG_Torsten Offline OP

User
TSG_Torsten  Offline OP

User

Joined: Mar 2005
Posts: 564
/www/europe/ germany/index.php
Thanks for your help.

But I still got the problem to transform the vertical speed when the ball hits a flat surface, the ground for example. Instead of flying upwards and still flying on x and y, it just fly upwards.



The upper part shows how it should look, the part below shows how it actually look if I use vec_bounce to change the movement.

Regards
TSGames

Last edited by TSG_Torsten; 06/05/09 11:19.

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1