Jump to content


Photo

bouncing projectile help


  • Please log in to reply
No replies to this topic

#1 sp@mbot

sp@mbot

    GMC Member

  • GMC Member
  • 2 posts
  • Version:Unknown

Posted 11 March 2012 - 10:34 PM

Hello
Im trying to make a metal slug type game.
Im having trouble with the grenades. In metal slug the grenades are to be thrown in arch, bounce up when they hit the floor and then explode the next time it hits the floor. (provided it doesn't hit enemies)

The collisions is giving me problems. when i try to get it to bounce up some times it will just fall through the floor or wall

and its not just from a jump, it happens all over at seemingly randome spots in the floor and wall
Posted Image


im usingRixeno's Pixel Perfect Collision Engine for collisions and its been working good till now

here is the code Im using
code for throwing grenade in player_step script @ line 226
if keyboard_check(kgrenade_key)
{  var obj; 

    if (can_shoot=1 and gnum<2)
    {
       
        obj=instance_create(x,y-130, obj_grenade);                
        gnum+=1;
        obj.direction=gdir;
        obj.speed=gpwr;
        obj.gravity=ggrav;
        can_shoot=0;
        alarm[0]=cool_down;
                
    }  
}
 

and here is code for grenade colision in obj_grenade step event


var collision;
collision=rppc_dir_step_solid(2.4,direction);

//this checks when the grenade collides with a virtical wall, and sets it to move in the opposite direction 
if place_meeting(x+12,y,obj_block) or place_meeting(x-12,y,obj_block)
{
hspeed = -hspeed  //bouncing off the wall with same side-speed
obj_player.gbounce-=1;
}

//bounces the grenade and reduces height and speed
if (collision==true  )
{
        vspeed = -vspeed/1.5  //after hitting the floor, the grenade will bouncing back up with less force
        hspeed = hspeed/1.5
        move_bounce_solid(0); 
        obj_player.gbounce-=1;  
           
}
//once grenade has bounced once it will be destroyed on the next collision 
   if(obj_player.gbounce<1)
  {instance_destroy();} 


here is link to dl the file
download

any help would be greatly appreciated

Edited by sp@mbot, 11 March 2012 - 10:35 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users