get id of creating object?

P

PieBaron

Guest
I'm trying to program a physics projectile which gets its velocity based on the orientation of the object which created it, but I since I have more than one object which can create this projectile I can't just address it by name..

// I can create the right velocity data

fGx = dcos(image_angle-90)* abs(fooVel);
fGy = dsin(image_angle-90)* -abs(fooVel);

projectile = instance_create(xOff,yOff, obj_projectile)

with(projectile){
physics_apply_force(phy_com_x, phy_com_y, fGx, fGy)
}

// But I don't know how to pass the fGx and fGy to the projectile object..
 

Roderick

Member
How I would do it:

Step 1: Create a script. Anything that calls the script "owns" the script, and you don't have to mess with with() functions.

Step 2: Inside the script, calculate the desired speed, create the object with a var thing = instance_create() command, and then apply a force or impulse to thing.

Step 3: Call the script from any object that is creating the thing.
 

Roderick

Member
Or, if you don't want to rewrite everything, just add projectile.creator = id right after creating projectile, and then each projectile will have a variable called "creator" that holds its creator's id.

Edit: That was supposed to be an edit not a reply. Apologies for the double post.
 
If fGx and fGy are instance variables and not local variables, then inside the 'with' block you can also refer to them using the 'other' keyword:

Code:
physics_apply_force(phy_com_x, phy_com_y, other.fGx, other.fGy)
 
Top