# How do I attach sprite to corner of rotating sprite W/O pin

Get help using Construct 2

### » Mon Aug 03, 2015 3:41 am

I need the math on how to attach a sprite to a position on another sprite that is rotating WITHOUT using the pin behavior.

I used to know it but I forgot.

Any help?
B
34
S
14
G
4
Posts: 251
Reputation: 4,074

### » Mon Aug 03, 2015 4:58 am

well, the easiest way - with no math involved - would be to create an image point on the rotating sprite, and then every tick position the other sprite to the image point.
B
99
S
35
G
20
Posts: 438
Reputation: 17,940

### » Mon Aug 03, 2015 10:10 pm

Without imagepoints you'll need 3 variables. Two for the positional offset from the center of the parent object and one for the angle difference.

For the positional offset you can either save it in rectangular (x,y) or polar(angle, distance) coordinates.

For rectangular:

every tick:
--- set child position to parent
--- child: move child.dx pixels at parent.angle degrees
--- child: move child.dy pixels at parent.angle+90 degrees
--- child: set angle to parent.angle+child.angdiff

For polar:

every tick:
--- set child position to parent
--- child: move child.dist pixels at parent.angle+child.ang degrees
--- child: set angle to parent.angle+child.angdiff

To calculate the offset it's probably easier to use polar.
set child.ang to angle(parent.x,parent.y,child.x,child.y)-parent.angle
set child.dist to distance(parent.x,parent.y,child.x,child.y)
set child.angdiff to child.angle-parent.angle
B
95
S
34
G
128
Posts: 5,494
Reputation: 81,676

### » Tue Aug 04, 2015 1:52 am

i was going to suggest setting the child's position to:

you would then have to add an angle offset that you add to the parent angle to get the child lined up to a particular spot on the parent image, but that is where just placing an imagepoint where you want the child makes the whole process a lot easier...
B
99
S
35
G
20
Posts: 438
Reputation: 17,940

### » Tue Aug 04, 2015 3:04 pm

Yep! Thanks @R0J0hound and @AllanR that's what i needed!
B
34
S
14
G
4
Posts: 251
Reputation: 4,074