| |
Collision Lines (gm6.1 Reg), I need an explanation
Grant |
|

John Freeman said
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![Sprite Comp Winner Badge (2) [*]](https://archive.mfgg.net/html/badges/scg2.gif) ![Sprite Comp Top 5 Badge (2) [*]](https://archive.mfgg.net/html/badges/sct2.gif) ![Drawing Comp Winner Badge (2) [*]](https://archive.mfgg.net/html/badges/dcg2.gif) ![Drawing Comp Top 5 Badge (1) [*]](https://archive.mfgg.net/html/badges/dct1.gif)
![Minigame Comp Winner Badge (1) [*]](https://archive.mfgg.net/html/badges/mcg1.gif) ![Minigame Comp Runner Up Badge (1) [*]](https://archive.mfgg.net/html/badges/mcr1.gif) ![Secret Santa Badge [*]](https://archive.mfgg.net/html/badges/present.gif)

Group: Members
Posts: 8260
Member No.: 2900
Joined: 31-October 06
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
collision_line() is a function that returns true or false (Boolean values). Therefore it can be used in such expressions as:
| CODE | if collision_line(x1, y1, x2, y2, obj, prec, notme) // You could optionally make this line read thus: if collision_line(x1, y1, x2, y2, obj, prec, notme) == true { [put statement here]; } |
This is basically the equivalent of asking: If an instance of object "obj" overlaps the line between point (x1,y1) and (x2,y2), then execute the statement; if one doesn't overlap it, don't execute it. A true/false value should replace "prec" indicating whether precise collision checking is used and a true/false value should also replace "notme" indicating whether the calling instance (in whose programming this code piece originates) should be checked or not if it is an instance of object "obj".
A statement containing collision_line() can go in any event it's needed in.
Just experiment around with it.
EDIT: Now I see that I didn't read your post carefully, and that I didn't fully answer your question. I'll think about it a bit more, assuming I have the time tonight.
This post has been edited by Grant on May 24 2008, 03:54 AM
--------------------
| QUOTE (oh youtube trolls) | | u guys r retarded hippocrates |
| QUOTE (Piemanthe3rd) | | Pie is not random. I wish people would realize this. |
|
|
|
Grant |
|

John Freeman said
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![Sprite Comp Winner Badge (2) [*]](https://archive.mfgg.net/html/badges/scg2.gif) ![Sprite Comp Top 5 Badge (2) [*]](https://archive.mfgg.net/html/badges/sct2.gif) ![Drawing Comp Winner Badge (2) [*]](https://archive.mfgg.net/html/badges/dcg2.gif) ![Drawing Comp Top 5 Badge (1) [*]](https://archive.mfgg.net/html/badges/dct1.gif)
![Minigame Comp Winner Badge (1) [*]](https://archive.mfgg.net/html/badges/mcg1.gif) ![Minigame Comp Runner Up Badge (1) [*]](https://archive.mfgg.net/html/badges/mcr1.gif) ![Secret Santa Badge [*]](https://archive.mfgg.net/html/badges/present.gif)

Group: Members
Posts: 8260
Member No.: 2900
Joined: 31-October 06
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
OK, maybe this might be crazy enough to work. Perhaps you could put something like this in the code of obj_laser:
if collision_line(x, y, x value of the originating cannon, y value of the originating cannon, obj_enemy, true (assuming precise collision checking; otherwise false), true) { with obj_enemy { if collision_line(other.x, other.y, x value of the originating cannon*, y value of the originating cannon*, self, true (assuming precise collision checking; otherwise false), true) { instance_destroy(); //replace this with whatever you want to happen to the enemy when it dies, if it's not this. } } }
*In these cases, express the x and y values of the originating cannon in such a way that the "with" statement can use them, similarly to how "other.x" and "other.y" were used within the "with" statement to refer to the x and y of the bullet.
Also please note that this might not work, as I'm not sure "self" works the way I think it does with collision_line().
This post has been edited by Grant on May 24 2008, 04:14 AM
--------------------
 | QUOTE (oh youtube trolls) | | u guys r retarded hippocrates |
| QUOTE (Piemanthe3rd) | | Pie is not random. I wish people would realize this. |
|
|
|
Grant |
|

John Freeman said
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![Sprite Comp Winner Badge (2) [*]](https://archive.mfgg.net/html/badges/scg2.gif) ![Sprite Comp Top 5 Badge (2) [*]](https://archive.mfgg.net/html/badges/sct2.gif) ![Drawing Comp Winner Badge (2) [*]](https://archive.mfgg.net/html/badges/dcg2.gif) ![Drawing Comp Top 5 Badge (1) [*]](https://archive.mfgg.net/html/badges/dct1.gif)
![Minigame Comp Winner Badge (1) [*]](https://archive.mfgg.net/html/badges/mcg1.gif) ![Minigame Comp Runner Up Badge (1) [*]](https://archive.mfgg.net/html/badges/mcr1.gif) ![Secret Santa Badge [*]](https://archive.mfgg.net/html/badges/present.gif)

Group: Members
Posts: 8260
Member No.: 2900
Joined: 31-October 06
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
| QUOTE (Sploder @ May 24 2008, 07:41 AM) | | @Grant, the way you have it there, it would work if there were only one obj_enemy. |
I tried to make it so that it would work with multiple ones. I think it would, though I'm not positive.
The way I meant it to be, the logic was supposed to be thus:
If there is a collision between the line from bullet to cannon and any instance(s) of obj_enemy, then have every obj_enemy active in the room execute the following independently: If it has the line from the bullet to the cannon intersecting it, then destroy it.
Thanks for the "id" tip, though. I was unsure about "self" to begin with because I had tried to use it in the past for collision_line(), unsuccessfully.
EDIT: And apparently it did work, from what Elyk said above (when he took your advice and changed "self" to "id"). But Elyk, if you haven't tested to make sure it works with more than one obj_enemy, I suggest you do that.
This post has been edited by Grant on May 24 2008, 11:13 PM
--------------------
| QUOTE (oh youtube trolls) | | u guys r retarded hippocrates |
| QUOTE (Piemanthe3rd) | | Pie is not random. I wish people would realize this. |
|
|
|
0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)
0 Members:
Track this topic
Receive email notification when a reply has been made to this topic and you are not active on the board.
Subscribe to this forum
Receive email notification when a new topic is posted in this forum and you are not active on the board.
Download / Print this Topic
Download this topic in different formats or view a printer friendly version.
[ Script Execution time: 0.0554 ] [ 13 queries used ] [ GZIP Enabled ] [ Server Load: 0.87 ]
| |