Fix position of actor with changing shape and fixed rotation

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

Comments

  • SocksSocks London, UK.Member Posts: 12,822
    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.

  • SocksSocks London, UK.Member Posts: 12,822
    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

  • SocksSocks London, UK.Member Posts: 12,822

    Demo attached:

  • imjustmikeimjustmike Member Posts: 450

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

    I tried googling for some more information on cos and sin and rotation calculations but it mostly went over my head - don't suppose you know any resources where I could learn more about this sort of thing?

Sign In or Register to comment.