#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Actor 2 constraining to Actor 1 but not rotating - Help

Posts: 785Member
edited November -1
I have my main actor 1 which I move and rotate around the screen.

I am constraining actor 2 to actor 1 with a slight offset, this part works great but when I rotate my main actor 2, actor 1 doesn't follow and I am having problems getting this part to work.

I have the following.

Actor 1 (main actor) have 2 real attributes I call TARGET X and TARGET Y

On actor 2 I have:
constrain attribute
self.position X to game.targetX+30 (slight offset)
self.position Y to game.targetY

I just can't work out what sort of rotate attribute I need to add so if follows in the right location when actor 1 rotates.

• Posts: 3,206Member
can you simply constrain self.Rotation To: game.targetRotation?

that's just off the top of my head...
it probably requires more math to maintain the angular velocity
• Posts: 785Member
It works the second actor is rotating on its own centrepoint the same as actor 1 but because I need to offset Actor 2 by + 30 pixels its making it always stay on the right of actor 1 and not rotate around with actor 1 if that makes sense.
• Posts: 3,206Member
right...

ok, try this:

Constrain Attribute
self.Rotation To: vectorToAngle( self.Position.X - game.targetX , self.Position.Y - game.targetY )

That might work...
Otherwise you're going to have to break out those trig books!

Joe
• Posts: 785Member
I saw a similar post but where is 'VectortoAngel' I can't find that in the expressions?
• Posts: 3,206Member
it's in there...
in the expression editor. the little 'e'
• Posts: 785Member
Found it - thanks. Still not working, but now I know that's there I will have a little play and see if I can stumble on the right formula.

Thanks for your help Joe
• Posts: 3,206Member
it will most likely be a combo of sine and cosine, but am not good at trig by any means...
good luck!
• Posts: 785Member
GOT IT! - Yes your right Joe in the end I had to use sine & cosine but now I have an offset Actor that rotates with the main Actor.
• Posts: 3,206Member
nice! please post the formula!
• Posts: 785Member
CONSTRAIN ATTRIBUTE
self.Position.X to 30*cos(game.TargetRotation)+game.TargetX
self.Position.Y to 30*sin(game.TargetRotation)+game.TargetY
• Posts: 817Member
JCFord I've been trying to figure this out for days now and I've tried to put together what I've found in this thread. Could you please go into more detail on how you did this?
• Posts: 817Member
bump
• Posts: 13Member
Hey I have been trying to work something similar out for a long time. Will this work to constrain a couple actors to the bottom two corners of an actor like tires on a car?
This discussion has been closed.