Distance between actors
NMansell
Member Posts: 143
Is there a coding way to set a distance between the actors?
Comments
That expression will measure the distance between two actors, and you can create a rule to do whatever when the distance is = or > or <
Can you please illustrate the rule?
This thread is three years old so I'm not sure ironDan is going to be responding but I'll see if I can help you out.
If you set the left side of the rule condition to "Numeric Expression" you can then type in or select the magnitude() function from the math functions drop-down menu. Be sure to select attribute names (e.g. game.TargetX) from the attribute drop-down menu instead of typing them in.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@NMansell
Create REAL game attributes TargetX and TargetY.
In one of your actors:
-CONSTRAIN TargetX to self.PositionX
-CONSTRAIN TargetY to self.PositionY
(Constrain if your actor will be moving otherwise just use Change)
In other actor you can check the distance by:
Here's what I need help with: This is what I have for my Daisy Chain of say 2 Actors, it works perfect , when there's no movement, all actors stay on top of each other, when there's movement by the lead Actor, the other Actor stays behind and follows. What I need help with is, How can I make it where I can set them apart but stay together at a set distance?
Constrain self.rotation to vectorToAngle(self.motion.linearVelocity.x,self.motion.linearVelocity.y)
Constrain self.motion.linearVelocity.X to 10*(ACTORTOFOLLOW.position.x-self.position.x)
Constrain self.motion.linearVelocity.Y to 10*(ACTORTOFOLLOW.position.y-self.position.y)
Thanks for all the time and help, really appreciate it.
@dellagarpo -- Give this a try.
The -75 is the distance behind the leader. (Its negative because its behind the leader.)
i'm sorry, i'm so exhausted can't think straight, lol... and a little drunk too haha
How would you rewrite this to add a distance of 100 pixels?
Constrain self.motion.linearVelocity.Y to 10*(ACTORTOFOLLOW.position.y-self.position.y)
Thanks!
didn't knew the game.targetX trick thanks guys
so far I constrain X of object A with a global variable and the same for object B with another global variable
than i used abs(ObjectA_X-ObjectB_X)
that gives me netto distance with no minus sign.
abs= absolute
My Apps
https://itunes.apple.com/de/artist/david-zobrist/id733552276
https://play.google.com/store/apps/developer?id=David+Zobrist&hl=de
Hmmm.... The short answer is you can't! You are trying to use the wrong equation. (That is like asking, "how can I make 25*10 equal 100?"
The equation I supplied is the correct one. And then you can change the "-75" to "-100"
The long answer is that you need to use some trig calculations. This is because you need to find the spot 100 pixels behind the lead actor. That spot designates the location that you want the follower actor to move to. But because the lead actor rotates, it takes a little trig to find the right x,y coordinate. (That x,y coordinate constantly changes as the lead actor rotates around.)