Jump to content


Photo

Collisions - How to get the id of the other object


  • Please log in to reply
6 replies to this topic

#1 Pancratius

Pancratius

    GMC Member

  • GMC:Member
  • 55 posts
  • Version:GM8

Posted 28 May 2012 - 06:03 PM

Hello All,

In my code I am creating a collision line. What i wish to do is to get the id of the instance that this line collides with. How do I do this?

I have tried using other, but it returned the object creating the collision line.

Any suggestions?

This is the code I am using:
collision_line(initialpos_x, initialpos_y, self.x+sin(shipdir)*Lscale*36,self.y+cos(shipdir)*Lscale*36, obj_asteroid, 1, 1)

regards,
Pancratius

#2 dannyjenn

dannyjenn

    GMC Member

  • GMC Member
  • 2084 posts
  • Version:Mac

Posted 28 May 2012 - 06:07 PM

I have tried using other, but it returned the object creating the collision line.

What object was the code in? Other should return the instance that collides with whatever the code is in... don't know why it would be returning itself...
  • 0

#3 Noele

Noele

    GMC Mentor

  • GMC Member
  • 2352 posts
  • Version:GM8.1

Posted 28 May 2012 - 06:10 PM

collision_line returns the instance ID of the other object or noone if there was not one.
inst = collision_line(initialpos_x, initialpos_y, self.x+sin(shipdir)*Lscale*36,self.y+cos(shipdir)*Lscale*36,
 obj_asteroid, 1, 1);
if(inst > 0){
  // inst contains the instance ID of the obj_asteroid
}

  • 0

#4 Pancratius

Pancratius

    GMC Member

  • GMC:Member
  • 55 posts
  • Version:GM8

Posted 28 May 2012 - 07:20 PM

Thank you :) Its working now.

Is there a website anywhere that holds all of the GML functions along with what they return etc?
If not I think I may start a document file, and record them as I go.

#5 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16814 posts
  • Version:GM:Studio

Posted 28 May 2012 - 07:25 PM

There is the manual... it has all the functions and a general explanation. Press f1 in GM to open it...
  • 0

#6 Pancratius

Pancratius

    GMC Member

  • GMC:Member
  • 55 posts
  • Version:GM8

Posted 28 May 2012 - 07:35 PM

oh ok, Thank you :)

#7 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 4733 posts
  • Version:GM8

Posted 28 May 2012 - 08:17 PM

And to answer the questions here:

other does not work with collision_line() or collision_rectangle() or any other collisions script. It only works with the Collision EVENTS. collision_line is not an event, it's a function/script, therefor other defaults to the calling instance. This is imporant to remember if you use the with statement. For example, you can use

with(instance_nearest(x,y,my_bullet))
hspeed=other.hspeed+2

This will set the hspeed of the nearest my_bullet to the hspeed of the object that has this script in it.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users