Page 1 of 1

Positioning Relative to Angle and Distance

PostPosted: Wed Mar 12, 2014 9:23 pm
by Boomlet
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

Re: Positioning Relative to Angle and Distance

PostPosted: Wed Mar 12, 2014 9:34 pm
by Aphrodite
Boomlet wrote: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")

Re: Positioning Relative to Angle and Distance

PostPosted: Wed Mar 12, 2014 9:37 pm
by Alyra Games
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?

Re: Positioning Relative to Angle and Distance

PostPosted: Wed Mar 12, 2014 9:38 pm
by Boomlet
Just to be super clear, I want to calculate the co-ordinates of the orange square.

Diag.png


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

Thanks!

Re: Positioning Relative to Angle and Distance

PostPosted: Wed Mar 12, 2014 9:39 pm
by Boomlet
@Alayra Games
Yes - relative to it if it moves.

Re: Positioning Relative to Angle and Distance

PostPosted: Wed Mar 12, 2014 9:42 pm
by Boomlet
Aphrodite - thanks, yes that looks like it could work. I'll give that a go.

Re: Positioning Relative to Angle and Distance

PostPosted: Wed Mar 12, 2014 9:53 pm
by Boomlet
That totally worked - thanks :)

Re: Positioning Relative to Angle and Distance

PostPosted: Thu Jun 04, 2015 4:19 pm
by quendera
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!