#### Howdy, Stranger!

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

# Fix position of actor with changing shape and fixed rotation

Posts: 450Member

Hey, I've got an actor that changes height based on attributes in the game. I have fixed the y position so that the actor's 'bottom' stays fixed whilst the top goes up and down. (constrain y to y + height/2)

However, I'm not sure how to do the same if the actor is at an angle since it's not just the y position that needs constraining, but the x too. I figure I need an offset based on the rotation (not just height/2), but don't know how I'd calculate that offset?

To make this even harder I want to constrain an actor, actor2, to the 'top' of this first actor, actor1. When actor1 isn't rotated, this is very simple as I just need to constrain the Y position based on the top of actor1. But I'll also need to constrain x.actor2 to the 'middle' of the 'top' of actor1.

Hopefully that makes sense? It probably doesn't...

If it does, could someone point me in the direction for calculating offsets of x positions based on the rotation of an actor?

Cheers,
Mike

• London, UK.Posts: 12,832Member
edited May 2016

You just need to multiply the height change by the cos/sin of the rotation of the actor to return the correct amount of movement. Hope that makes sense.

• London, UK.Posts: 12,832Member
edited May 2016

Probably doesn't make sense . . . so here is an example

Example of a normal (not at an angle) growing shrinking actor:

Constrain height to 100 * sin( game.Time * 200) + Your overall Y height
Constrain Y position to (Height /2) + Your overall Y position

Example of an angled growing shrinking actor:

Constrain height to 100 * sin( game.Time * 200) + Your overall Y height
Constrain X to (Height /2) * sin( Rotation )+ Your overall X position
Constrain Y to (Height /2) * cos( Rotation )+ Your overall Y position

• London, UK.Posts: 12,832Member

Demo attached:

xx.zip 155.4K
• Posts: 450Member

@Socks That's absolutely fantastic, thank you so much.