Bullets going through moving wall (shield)

A place for people with an interest in developing new shmups.
Post Reply
NeoBahamut
Posts: 33
Joined: Sun Mar 13, 2005 10:41 am

Bullets going through moving wall (shield)

Post by NeoBahamut »

Well, I am trying to make bullets bounce off a shield (that is scrolling with the screen). So, we have one object moving towards the right (shield) and a lot of objects moving towards the left (bullets). It seems whatever I do, some bullets will always move THROUGH the shield.

Speed of the bullets differ. Speed of the shield is 1 (as the scrolling view), meaning it looks like it's not moving at all (against the scrolling background).

I have tried all variants of the D&D collision+bounce commands, plus a collision_line code that I picked up from someone (below). Does anyone have an ultimate solution for moving objects and collisions? Nothing seems to be 100% perfect…

Bullet:

In "End Step"

Code: Select all

/**
*  Accurate collisions for small & fast moving objects (by ArKano)
*
*
*  The collision checking is written at the end of the step,
*  when the object has already moved. Then, we check for collisions.
*  If we imagine a line going from our current 
*  position to our previous position, will it intersect a wall?
*
*  Note: this function ONLY checks for collisions with a line, it does not 
*        draw the line.
*  Note: global.collide turns collisions on and off, that is its only purpose.
*        If you turn the collisions off and slo-mo on, you can clearly see why
*        small fast moving objects are problematic: they move so fast
*        that they jump through walls, without actually touching them:
*        
*        In the next diagrams, "o" is a bullet and "| |" is a wall:
*
*        Step "n":
*        o      | | 
*
*        Step "n+1":
*             o | |
*
*        Step "n+2":
*               | | o
*
*        (GM only detects a collision when this happens):
*               |o| 
*     
*        So we will use a line to detect collisions (x is the previous position):    
*        Step "n+2":
*           x---|-|-o
*/

if (collision_line(x,y,xprevious,yprevious,wall,true,false) && global.collide)
{
    /**
    *  We use a new custom collision event, the user0.
    *  So when the bullet collides with a wall, 
    *  the user0 event will be executed. You could also write 
    *  right here the reaction you want to take place, but 
    *  i like to be tidy. ;) 
    */
    event_user(0); 
}
In User Defined 0:

Code: Select all

/**
*  This is our "collision with wall" event.
*/
//Jump to the previous position, that is, just before colliding with the wall.
x = xprevious;
y = yprevious;
/**
*   We move towards the wall until we touch it 
*  (this avoids seeing the bullet bounce before actually touching the wall.
*   Try to comment the following line to see what i mean.)
*/
move_contact_all(direction,speed);
//Decrease the speed:
speed = 5;
//Reverse the direction to make it bounce:
direction -= 180;
Control:

In Create:

Code: Select all

global.collide = true;
User avatar
worstplayer
Posts: 861
Joined: Sun Jun 17, 2007 6:48 pm
Location: Slovakia

Re: Bullets going through moving wall (shield)

Post by worstplayer »

Looks like that function doesn't take into account movement of the shield itself. Can't tell you how exactly to do it without seeing the rest of the code, maybe add that movement to x = xprevious;y = yprevious ???

EDIT:

direction -= 180;
This can be a problem too. Due to movement of the shield, it can reverse into already shielded place, and bounce back and forth until the shield moves past it. Try changing it to a fixed value.
"A game isn't bad because you resent it. A game is bad because it's shitty."
User avatar
Rozyrg
Posts: 918
Joined: Wed Feb 11, 2009 12:03 am
Location: Southeast USA

Re: Bullets going through moving wall (shield)

Post by Rozyrg »

I'm thinking it could be the old 0/360 degree problem.... the direction might be going lower than zero, which causes it to do weird stuff.

Basically, you'd have to define what happens when it gets too high or low to make it successfully wrap back around to 360 and vice versa. Should be simple enough; but I could never quite tackle it. >_>
User avatar
monkeyman
Posts: 223
Joined: Wed Nov 14, 2007 8:53 pm

Re: Bullets going through moving wall (shield)

Post by monkeyman »

If the shield is right at the back of the screen you could always cheat and simply have bullets reverse direction once their x co-ordinate is lower than 'view_xview' (I think that's the correct term for the left of the screen). You could still have the problems worstplayer mentioned if you use the direction -=180 though.
My shmup Projects
Finished: Invader! -- Tri Hunter -- Proj Raiden
WIP: Infinity Squadron
NeoBahamut
Posts: 33
Joined: Sun Mar 13, 2005 10:41 am

Re: Bullets going through moving wall (shield)

Post by NeoBahamut »

Terribly sorry for not getting back earlier!

So, rotation could definitely have something to do with it, but I wouldn't say it's the whole problem. Bullets still go through the shield at straight angles...

I've tried the custom script in a non-moving room and it seems to be working better, although not 100%.

Anyhow, the problem should be a pretty basic one, since many games are likely dependent on two moving objects colliding with each other. Seems a bit strange that GM handles this so poorly...
User avatar
ShmupSamurai
Posts: 473
Joined: Fri Jan 15, 2010 2:15 am
Location: Texas

Re: Bullets going through moving wall (shield)

Post by ShmupSamurai »

Interesting problem.... :?
Use Shumpman's advice!

"USE A BOMB!"
NeoBahamut
Posts: 33
Joined: Sun Mar 13, 2005 10:41 am

Re: Bullets going through moving wall (shield)

Post by NeoBahamut »

Hmm, I think I might be getting somewhere. I will do some testing and then get back again ;)
User avatar
null1024
Posts: 3811
Joined: Sat Dec 15, 2007 8:52 pm
Location: ʍoquıɐɹ ǝɥʇ ɹǝʌo 'ǝɹǝɥʍǝɯos
Contact:

Re: Bullets going through moving wall (shield)

Post by null1024 »

worstplayer wrote:direction -= 180;
This can be a problem too. Due to movement of the shield, it can reverse into already shielded place, and bounce back and forth until the shield moves past it.
GM autosanitizes [internally I think, not sure if it directly remaps overlarge and underlarge values back to 0-359] all these numbers, so this shouldn't be a problem...
Come check out my website, I guess. Random stuff I've worked on over the last two decades.
User avatar
Rozyrg
Posts: 918
Joined: Wed Feb 11, 2009 12:03 am
Location: Southeast USA

Re: Bullets going through moving wall (shield)

Post by Rozyrg »

Yeah, you'd think that'd be the case; but it still seems to happen.

To illustrate:
Image
Basically, what's happening is that lower right shot should be bending the other way; but it's starting direction is pretty close to 0/360, so when it tries to adjust itself (by adding to or subtracting from it's direction), it ends up 'over the line' ..
User avatar
null1024
Posts: 3811
Joined: Sat Dec 15, 2007 8:52 pm
Location: ʍoquıɐɹ ǝɥʇ ɹǝʌo 'ǝɹǝɥʍǝɯos
Contact:

Re: Bullets going through moving wall (shield)

Post by null1024 »

Sanitize it yourself then, use a temp var, and keep subtracting/adding 360 to your value until it's within the correct bounds [if it's lower than 0, add, higher, subtract]. Do this after everything, right before you actually set the direction.
Come check out my website, I guess. Random stuff I've worked on over the last two decades.
NeoBahamut
Posts: 33
Joined: Sun Mar 13, 2005 10:41 am

Re: Bullets going through moving wall (shield)

Post by NeoBahamut »

I noticed that the collision works better on thicker lines (in this case a shield), so I think I will leave it at that for now and get back to fine tuning (or re-tuning) at a later stage...
Post Reply