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

Get help using Construct 2

Post » 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?
Follow me on Twitter @evgLabs
B
34
S
14
G
4
Posts: 251
Reputation: 4,074

Post » 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
94
S
33
G
20
Posts: 438
Reputation: 17,605

Post » 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
91
S
31
G
102
Posts: 5,232
Reputation: 67,250

Post » Tue Aug 04, 2015 1:52 am

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

child x = Parent.X+cos(Parent.Angle)*ParentRadius
child y = Parent.Y+sin(Parent.Angle)*ParentRadius

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
94
S
33
G
20
Posts: 438
Reputation: 17,605

Post » Tue Aug 04, 2015 3:04 pm

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


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, luck1210, Yahoo [Bot] and 6 guests