# Positioning Relative to Angle and Distance

Get help using Construct 2

### » Wed Mar 12, 2014 9:23 pm

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
B
7
S
1
Posts: 16
Reputation: 732

### » Wed Mar 12, 2014 9:34 pm

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")
Last edited by Aphrodite on Wed Mar 12, 2014 9:37 pm, edited 1 time in total.
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
54
S
23
G
18
Posts: 2,123
Reputation: 17,200

### » Wed Mar 12, 2014 9:37 pm

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?
B
10
S
2
Posts: 135
Reputation: 1,090

### » Wed Mar 12, 2014 9:38 pm

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!
You do not have the required permissions to view the files attached to this post.
B
7
S
1
Posts: 16
Reputation: 732

### » Wed Mar 12, 2014 9:39 pm

@Alayra Games
Yes - relative to it if it moves.
B
7
S
1
Posts: 16
Reputation: 732

### » Wed Mar 12, 2014 9:42 pm

Aphrodite - thanks, yes that looks like it could work. I'll give that a go.
B
7
S
1
Posts: 16
Reputation: 732

### » Wed Mar 12, 2014 9:53 pm

That totally worked - thanks
B
7
S
1
Posts: 16
Reputation: 732

### » Thu Jun 04, 2015 4:19 pm

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!
B
10
S
2
Posts: 27
Reputation: 617