• 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!

[solved] how to move an object in the image angle of a different object

N

Nuthole

Guest
ok so i need to make the image angle of objectA the direction of objectB, but when i do "launch = image_angle" on objectA, objectB does not understand the "launch" variable. how do i make objectB understand?
 
S

spirit_games

Guest
Could you clarify a bit? What is the variable launch for? Does it store the objects direction? You can call out variables from other objects by stating the object before the variable.

If you wanted objectA’s image_angle to equal objectB’s launch direction you could type:

If objectB is calling the code...
Code:
objectA.launch = image_angle
If objectA is calling the code...
Code:
objectB.image_angle = launch
 
N

Nuthole

Guest
Could you clarify a bit? What is the variable launch for? Does it store the objects direction? You can call out variables from other objects by stating the object before the variable.

If you wanted objectA’s image_angle to equal objectB’s launch direction you could type:

If objectB is calling the code...
Code:
objectA.launch = image_angle
If objectA is calling the code...
Code:
objectB.image_angle = launch
Hi, thank you so much! i have been having this problem for actual days now and this is the first thing that actually worked, the working code is: motion_add(objectA.launch, 17) for anyone who sees this in the future, thanks!
 
Just remember that there's a big difference between objects (the blueprint for instances) and instances themselves (the things that exist in your game). I feel like both the "answerer" and asker of this question don't really understand this vital difference. If you have more than one objectA in this scenario, you will get buggy code. What you should be doing is storing the instance ID of objectB when it is being created and then using that ID to tell the instance of objectB what to do, something like this (this is from within objectA):
Code:
var inst = instance_create_layer(x,y,"layer",objectB); // Store the instance ID of the objectB instance that was just created in a temp variable called "inst"
with (inst) { // Now we use with() to tell muddle with the insides of the instance of objectB that was just created, using the previously created temp variable holding said instance ID "inst"
   launch = other.image_angle; // If this code is being run from within objectA then other in this circumstance will refer to objectA, so we can use other.image_angle to get the image_angle of objectA and set an instance variable called launch within objectB to it.
}
Then you can simply do:
Code:
motion_add(launch,17);
Within objectB and it will aim wherever the image_angle of objectA was facing when objectB was created.
 

FrostyCat

Redemption Seeker
What you should be doing is storing the instance ID of objectB when it is being created and then using that ID to tell the instance of objectB what to do, something like this (this is from within objectA):
Code:
var inst = instance_create_layer(x,y,"layer",objectB); // Store the instance ID of the objectB instance that was just created in a temp variable called "inst"
with (inst) { // Now we use with() to tell muddle with the insides of the instance of objectB that was just created, using the previously created temp variable holding said instance ID "inst"
   launch = other.image_angle; // If this code is being run from within objectA then other in this circumstance will refer to objectA, so we can use other.image_angle to get the image_angle of objectA and set an instance variable called launch within objectB to it.
}
Then you can simply do:
Code:
motion_add(launch,17);
Within objectB and it will aim wherever the image_angle of objectA was facing when objectB was created.
While the members before you have some work to do when it comes to objects vs. instances, looks like you have some work to do as well when it comes to event timing. If you put the motion_add() line in the Create event of objectB, it will still trigger too early.

One alternative is to put the motion_add() line in a User event and call that:
Code:
with (instance_create_layer(x, y, "layer", objectB)) {
  launch = other.image_angle;
  event_user(14);
}
Code:
// User event 14
motion_add(launch, 17);
A lesser alternative is to put the motion_add() line with objectA like this:
Code:
with (instance_create_layer(x, y, "layer", objectB)) {
  motion_add(other.image_angle, 17);
}
I consider this worse than the user event solution because it puts the definition of properties for objectA in the hands of objectB.
 
Oh, I didn't intend for them to put the motion_add in the Create Event (you'll notice I never actually said Create Event), though reading the post back I can see that that's the implication. I should've been more explicit in my "Within objectB" statement about the fact that it has to be done in a single step fire Alarm, a triggered User Event or within a flag variable if statement in the Step Event (though of course, the User Event is best way).
 
Top