Powered by Invision Power Board

 
    Reply to this topicStart new topicStart Poll

> Collision Lines (gm6.1 Reg), I need an explanation
United States
Elyk
Posted: May 23 2008, 09:43 PM
Quote Post


Standard Member
[*][*][*][*]

Group Icon
Group: Members
Posts: 6604
Member No.: 3808
Joined: 22-May 07

Status: (0d) [--]


Okay, I have these laser bullets that need to go about 100 pixels per step to look good. The problem is that they pass right over the enemies. Speeding up the room would be inefficient because I would need to change all of my previous coding to work. The next thing I thought of was collision lines, I have quite a lot of experience with GM but I have never needed to use collision lines, and what event and object they need to go into. So if someone could explain exactly what I need to and where the events need to be placed I would be very thankful. The objects are obj_enemy, obj_laser(which also is drawing a primitive line from itself to the cannon), obj_lasercannon(which is not a moving and rotating instance), and obj_block (which destroys the laser object)


--------------------
user posted image
PMEmail PosterUsers WebsiteAOLMSN
Top
Unspecified
Miaxis
Posted: May 24 2008, 03:42 AM
Quote Post


hagan bromas
[*]

Group Icon
Group: Members
Posts: 1799
Member No.: 2793
Joined: 12-October 06

Status: (0d) [--]


Actually collision_- codes work exactly like the collision event.


--------------------
user posted image

user posted imageuser posted imageuser posted imageuser posted image
PMEmail PosterUsers WebsiteMSN
Top
United States
Grant
Posted: May 24 2008, 03:53 AM
Quote Post


John Freeman said
[*][*][*][*][*]
[*][*][*]

Group Icon
Group: Members
Posts: 8260
Member No.: 2900
Joined: 31-October 06

Status: (0d) [--]


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


--------------------
user posted image

QUOTE (oh youtube trolls)
u guys r retarded hippocrates

QUOTE (Piemanthe3rd)
Pie is not random. I wish people would realize this.
PMEmail PosterUsers WebsiteAOLMSN
Top
United States
Grant
Posted: May 24 2008, 04:14 AM
Quote Post


John Freeman said
[*][*][*][*][*]
[*][*][*]

Group Icon
Group: Members
Posts: 8260
Member No.: 2900
Joined: 31-October 06

Status: (0d) [--]


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


--------------------
user posted image

QUOTE (oh youtube trolls)
u guys r retarded hippocrates

QUOTE (Piemanthe3rd)
Pie is not random. I wish people would realize this.
PMEmail PosterUsers WebsiteAOLMSN
Top
Unspecified
Miaxis
Posted: May 24 2008, 04:25 AM
Quote Post


hagan bromas
[*]

Group Icon
Group: Members
Posts: 1799
Member No.: 2793
Joined: 12-October 06

Status: (0d) [--]


Hmmmm.....checking the collision from an external object?Yeah,kinda sounds crazy.


--------------------
user posted image

user posted imageuser posted imageuser posted imageuser posted image
PMEmail PosterUsers WebsiteMSN
Top
United States
Sploder
Posted: May 24 2008, 06:41 AM
Quote Post


Standard Member
[*][*][*][*]

Group Icon
Group: Members
Posts: 781
Member No.: 2317
Joined: 12-July 06

Status: (0d) [--]


@Grant, the way you have it there, it would work if there were only one obj_enemy. Also, if self doesn't work, you can always replace it with id.

This post has been edited by Sploder on May 24 2008, 06:41 AM
PMEmail Poster
Top
United States
RetroXYZ
Posted: May 24 2008, 07:20 AM
Quote Post


Standard Member
[*][*]

Group Icon
Group: Members
Posts: 2714
Member No.: 4325
Joined: 27-August 07

Status: (0d) [--]


Wait for ENIGMA r3, then use the awesome collision_primitive.

Or you could just do collision_rectangle between the x & y previous and x & y, checking for a line in the middle.

This post has been edited by RetroXYZ on May 24 2008, 07:21 AM
PMEmail PosterMSN
Top
Unspecified
Miaxis
Posted: May 24 2008, 07:22 AM
Quote Post


hagan bromas
[*]

Group Icon
Group: Members
Posts: 1799
Member No.: 2793
Joined: 12-October 06

Status: (0d) [--]


QUOTE (RetroXYZ @ May 24 2008, 02:20 PM)
Wait for ENIGMA r3, then use the awesome collision_primitive.

Heīs using Game Maker.And I donīt think he wants to switch to another program since(I think so) heīs pretty good at GM,even to one thatīs not released yet.


--------------------
user posted image

user posted imageuser posted imageuser posted imageuser posted image
PMEmail PosterUsers WebsiteMSN
Top
United States
RetroXYZ
Posted: May 24 2008, 07:29 AM
Quote Post


Standard Member
[*][*]

Group Icon
Group: Members
Posts: 2714
Member No.: 4325
Joined: 27-August 07

Status: (0d) [--]


ENIGMA is exactly the same, and about 10x faster, and much better. It even imports .gmd, .gm6, and .gmk files. Read first.
PMEmail PosterMSN
Top
Unspecified
Miaxis
Posted: May 24 2008, 07:34 AM
Quote Post


hagan bromas
[*]

Group Icon
Group: Members
Posts: 1799
Member No.: 2793
Joined: 12-October 06

Status: (0d) [--]


So itīs an inofficial sequel to GM?btw why r3?


--------------------
user posted image

user posted imageuser posted imageuser posted imageuser posted image
PMEmail PosterUsers WebsiteMSN
Top
United States
Elyk
Posted: May 24 2008, 08:27 AM
Quote Post


Standard Member
[*][*][*][*]

Group Icon
Group: Members
Posts: 6604
Member No.: 3808
Joined: 22-May 07

Status: (0d) [--]


Thanks, I got it working. :D

The only thing I had to change was in the second collision line so it would check id rather than self and change notme to false.



--------------------
user posted image
PMEmail PosterUsers WebsiteAOLMSN
Top
United States
Grant
Posted: May 24 2008, 11:12 PM
Quote Post


John Freeman said
[*][*][*][*][*]
[*][*][*]

Group Icon
Group: Members
Posts: 8260
Member No.: 2900
Joined: 31-October 06

Status: (0d) [--]


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


--------------------
user posted image

QUOTE (oh youtube trolls)
u guys r retarded hippocrates

QUOTE (Piemanthe3rd)
Pie is not random. I wish people would realize this.
PMEmail PosterUsers WebsiteAOLMSN
Top
United States
Elyk
Posted: May 25 2008, 08:33 AM
Quote Post


Standard Member
[*][*][*][*]

Group Icon
Group: Members
Posts: 6604
Member No.: 3808
Joined: 22-May 07

Status: (0d) [--]


when I tested there were four enemies. Using self did nothing, using obj_enemy again destroyed all but the one that was in the line, and id destroyed the one that was in the line.


--------------------
user posted image
PMEmail PosterUsers WebsiteAOLMSN
Top
0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)
0 Members:

  Topic Options Topic Options Reply to this topicStart new topicStart Poll

 




[ Script Execution time: 0.0554 ]   [ 13 queries used ]   [ GZIP Enabled ]   [ Server Load: 0.87 ]