• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Fast collision line?

L

lord_berto

Guest
bullet code.png is there a way to create a faster collision line code?

if I enable it inside a while loop, my FPS go from 800 to 200.
 
Last edited by a moderator:

GMWolf

aka fel666
Why use collision_line in a while loop?
are you using the built in collision line or your own varient?
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
Try enabling fast collision system in first Global Game Settings' tab, if the GMS version you use has it. Otherwise tell what you're trying to do and/or show the code.
 
L

lord_berto

Guest
Why use collision_line in a while loop?
are you using the built in collision line or your own varient?
im using the built in function, I'm using it in a while loop because its inside a script for bullet collision.

//collision = place_meeting walls or enemy

while (!collision && point_distance(player_o.x,player_o.y,temp_x,temp_y) < 1400)
{


if instance_exists(enemy)
{
var nearest=instance_nearest(temp_x,temp_y,enemy);

if point_distance(temp_x,temp_y,nearest.x,nearest.y)<=35
{
if !collision_line(temp_x,temp_y,nearest.x,nearest.y,wall_o,0,1)
{

nearest.nearMiss=1
}
}
}




temp_x += lengthdir_x(4,temp_dir)//point_direction(player_o.x-1+lengthdir_x(dist,temp_dir),player_o.y-1+lengthdir_y(dist,temp_dir),mx2+view_xview,my2+view_yview));
temp_y += lengthdir_y(4,temp_dir)//point_direction(player_o.x-1+lengthdir_x(dist,temp_dir),player_o.y-1+lengthdir_y(dist,temp_dir),mx2+view_xview,my2+view_yview));
collision = (position_meeting(temp_x,temp_y,wall_o) or ( position_meeting(temp_x,temp_y,zombie1_o) ) );


}


if the bullet FLYS near the enemy it will run a code inside the enemy.
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
In the bullet step event you could:

Code:
with(enemy) {
   if (other distance to this is < 1400) {
      if (!collision line between this and other) {
         could_be_near_miss = true;
         alarm[0] = 12;
      }
   }
}
in the alarm0 event of the enemy
Code:
if (could_be_near_miss) {
    is_near_miss = true;
    //do whatever you want with the near miss;
    show_debug_message("that was close!")
}
in bullet collision with enemy event
Code:
could_be_near_miss = false;
Just read the all post and understood what you are trying to do,
here is a pseudo-code, try it out..

Explanation::
when the bullet is near enough to the enemy and there is no collision line with the wall, then
it can be a near miss OR a hit!! so let's say it could_be_near_miss... the alarm is just to work as a verification if the bullet missed or hit... if after 12 frames it didn't hit... then it near missed... if it hit then you cancel the could_be_near_miss so the near miss could doesn't get triggered!
 
Last edited:
L

lord_berto

Guest
In the bullet step event you should:

1) check if distance to bullet is < than whatever you want!!
2) if 1) is true: check to see if there is no collision line between the bullet and the enemy
3) if 2) is true: do something
4) move the bullet!
so toss out using while loop? would it be better to do bullets like that? im still figuring out the best way for my bullets to work..
 
L

lord_berto

Guest
In the bullet step event you could:

Code:
with(enemy) {
   if (other distance to this is < 1400) {
      if (!collision line between this and other) {
         could_be_near_miss = true;
         alarm[0] = 12;
      }
   }
}
in the alarm0 event of the enemy
Code:
if (could_be_near_miss) {
    is_near_miss = true;
}
in bullet collision with enemy event
Code:
could_be_near_miss = false;
Just read the all post and understood what you are trying to do,
here is a pseudo-code, try it out..
if this code is placed into my while loop code for my bullet, it essential does the same thing and becomes slow. if my bullets were actual projectiles flying at 12 pixels per frame the code would work though..
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
Read my edited post above! ;) you don't need the while loop!!

even better you can:

enemy step event
Code:
with(bullet) {
   if (other distance to this is < 1400) {
      if (!collision line between this and other) {
         other.could_be_near_miss = true;
         other.alarm[0] = 12;
      }
   }
}
...here other is the enemy instance...

in the alarm0 event of the enemy
Code:
if (could_be_near_miss) {
    is_near_miss = true;
    //do whatever you want with the near miss;
    show_debug_message("that was close!")
}
in the enemy event - collision with the bullet
Code:
could_be_near_miss = false;
Explanation::
when the bullet is near enough to the enemy and there is no collision line with the wall, then
it can be a near miss OR a hit!! so let's say it could_be_near_miss... the alarm is just to work as a verification if the bullet missed or hit... if after 12 frames it didn't hit... then it near missed... if it hit then you cancel the could_be_near_miss so the near miss code doesn't get triggered!

EDIT : I just changed the code to the enemy event as there are less enemies then bullets so... the number of code executions is less
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
if this code is placed into my while loop code for my bullet, it essential does the same thing and becomes slow. if my bullets were actual projectiles flying at 12 pixels per frame the code would work though..
your bullets are not projectiles?! or instances?!
ahhhhh okay then, let me think!
 
A

anomalous

Guest
Yes, this doesn't seem to be the way to approach that, its not the function that is slow.
Your picture however is a good visual! If you can use an object for your bullet, its easier. You say you don't so I'll answer that (looks like someone just offered a bullet type collision).

First, find the "length" if the ray you use for the bullet.
If you allow multiple enemies hit (infinite pierce), then the length is from the gun to the first wall it hits.
If it also stops at an enemy, its the first wall or enemy hit hits. That's the bullet "ray".
You can use this to determine that:
http://www.gmlscripts.com/script/range_finder

Let's assume you can figure that out and figure out the instance id of the the enemy that was hit (if any), or each id (if pierce), putting that in a variable or a list as needed.
So the foe hit, you know the instance id(s).

Make a follower object for each enemy that has a collision mask the size of the "whizzed by" dimensions.
When you create it, put the instance id of the "owner enemy" in there, "owner_id" or something.

Once you determined who was hit, consider using this;
http://www.gmlscripts.com/script/collision_line_list
Use this to get collision line to all the FOLLOWER objects.
remove from this list of follower objects, each instance whose owner_id was actually hit (first step above). You don't care about whizz by if they were properly hit!

This is your list of whizzed by follower objects whose owner_ids were not hit.

Now, you apparently want to check if there is a wall separating the enemy, from the bullet path. I suppose you can find the line from your foe (who was whizzed by), center, to the bullet "ray" (see above), that is orthogonal to it. Check collision line against wall (a plain collision line) from foe center to the collision line point (That's orthogonal). If no collision, its a proper whizzed by, else, ignore it.

*edited to be more clear
 
Last edited by a moderator:
Top