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);
}
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;
In Create:
Code: Select all
global.collide = true;