Positioning Relative to Angle and Distance

0 favourites
  • 8 posts
  • Hi

    This seems like it shouldn't be that hard but I feel like I've hit a wall. Any help would be gratefully received.

    I want to position sprite01 relative to sprite02

    Sprite01 has two local variables: angle, and distance.

    I want to position sprite02 relative to sprite 01 according to the angle and distance stored in the local variables of sprite 01

    Should I be using trigonometry here or am I missing something really obvious?!

    Thanks

  • Hi

    This seems like it shouldn't be that hard but I feel like I've hit a wall. Any help would be gratefully received.

    I want to position sprite01 relative to sprite02

    Sprite01 has two local variables: angle, and distance.

    I want to position sprite02 relative to sprite 01 according to the angle and distance stored in the local variables of sprite 01

    Should I be using trigonometry here or am I missing something really obvious?!

    Thanks

    you could use the Angle(x1, y1, x2, y2) and distance(x1, y1, x2, y2) expressions I think for that, like this:

    Sprite01 : Set instance variable distance to: distance(Sprite01.X, Sprite01.Y, Sprite02.X, Sprite02.Y)

    Sprite01 : Set instance variable angles to: angle(Sprite01.X, Sprite01.Y, Sprite02.X, Sprite02.Y)

    EDIT: I think I understood that you wanted to store the angle and distance, but if you'd rather set the position using this, then you'd have to:

    Sprite02 : Set X to Sprite01.distance*cos(Sprite01.angles)

    Sprite02 : Set X to Sprite01.distance*sin(Sprite01.angles)

    (I used the name "Angles" for the variable since I am not sure you can use the word "angle")

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • What do you mean by "relative"? Do you mean in front of it? Or should sprite01 keep the angle, distance and everything else relevant to sprite02 if it moves?

  • Just to be super clear, I want to calculate the co-ordinates of the orange square.

    [attachment=0:11531gzl][/attachment:11531gzl]

    I know:

    • Green square co-ordinates
    • Angle (potentially any value between 0 and 180 (+ or -)
    • Distance

    Thanks!

  • ALAYRA Games

    Yes - relative to it if it moves.

  • Aphrodite - thanks, yes that looks like it could work. I'll give that a go.

  • That totally worked - thanks

  • Hello Boomlet,

    I'm working on a project where I'm faced with exactly your issue. If you'd be so kind, could you share your .capx?

    I'm not quite understanding how you made the variable expressions.

    Thanks!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)