# How do I do Pin with events?

0 favourites
• 12 posts
From the Asset Store
14 amazing sound files of game events like Level Ups, Level Completes, object spawn, object taking etc.
• Hi, I'm wondering what the math is to perform Pin Position & Angle with just events (not using the Pin Behavior). i.e. Set Position etc...

I'm sure someone on here has done it! thanks!

• Give the object you want to pin three instance variables.

a - angle from other object

d - distance from other object

ra - relative angle from other object

Then to set it up you’d do an event like this: for this example we are pinning the blue object to the red object.

Start of layout

— blue: set a to angle(red.x,red.y,blue.x,blue.y)-red.angle

— blue: set d to distance(red.x,red.y,blue.x,blue.y)

—blue: set ra to blue.angle-red.angle

Then the positioning would be:

Every tick

— blue: set position to red

— blue: move self.d pixels at angle self.a+red.angle

— blue: set angle to self.ra+red.angle

That’s basically it. When there are multiple objects to pin to you’d want to store the uid and stuff.

• R0J0hound thanks!

I guess I was over thinking it...I thought it was going to be something like this:

``````x_pin = Sprite.x - 50 * cos(Sprite.angle)
y_pin = Sprite.y + 50 * sin(Sprite.angle)

Every tick set position SpritePin to x=x_pin y=y_pin
``````

although this code wasn't working right.. but I think maybe it could?

• You don't have to make an offset if you use image points.

Not that we can set those at run time.

• Using sin/cos like that is basically what the “move at angle” action does. So setting the position could be like this instead, which is exactly the same.

Every tick

— Blue: set x to red.x + self.d*cos(self.a+red.angle)

— Blue: set y to red.y + self.d*sin(self.a+red.angle)

— blue: set angle to self.da+ red.angle

• I'm so confused...

here's what I have so far... I'd like to do it with 2 events: set position and set angle

• I need a link on learning vector math with cos and sin... does anyone know a good source for this kind of math specifically geared for gamedev?

EDIT:

doesn't really help in the now.. but it is something I need to study - I seriously hate not understanding it.

• I’m replying on my phone and I’m having technical issues opening your file in c3.

There are some nice interactive tutorials here. One covers vector math with sin/cos. Angles on there are counterclockwise instead of construct’s clockwise but the math works the same.

demoman.net

• R0J0hound oh sorry.. I always mess up the Google Link to be share by all

• ## Try Construct 3

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

Construct 3 users don't see these ads
• demoman.net

wow.. thanks, that's a really cool interactive demo!

• Opened your link. The technical issue was that when i download it on my phone it adds a .zip to the end of the filename and c3 won't open it then. Anyways I have no help other than it's not following what I wrote in my post. Here's an implementation of what i wrote:

dropbox.com/s/6p5pefe0vex89e7/arrow_pin.capx

• Your project isn't following what I wrote in my post. Anyways here's an example:

dropbox.com/s/6p5pefe0vex89e7/arrow_pin.capx

• 12 posts