How do I use a pin style behavior using trigonometry or math

Get help using Construct 2

Post » Sat Aug 29, 2015 11:48 pm

this is probably a very basic thing in every video game taken for granted but, I am totally lost when trying to understand the SOHCAHTOA
A way of remembering how to compute the sine, cosine, and tangent of an angle.

SOH stands for Sine equals Opposite over Hypotenuse.

CAH stands for Cosine equals Adjacent over Hypotenuse.

TOA stands for Tangent equals Opposite over Adjacent.


:o :?

Well, it turns out understanding this is hugely important in game design and still is only considered to be ENTRY LEVEL trigonometry.. lol.... :,,( my tears

But anyway, I was wondering how do I pin an object to another using this? Using Angle() (Atan2) or whatever? I have no clue. I have seen examples but dont understand it at all.

Lets say there is a rotating chair, and I want the player to always Stand behind the chair as it rotates (like 10 feet behind) and always face the same direction and the chair and stay relative to its position? D:
B
4
Posts: 27
Reputation: 254

Post » Sun Aug 30, 2015 1:32 am

Pinning is fairly straightforward. Given two objects, A and B, the pinned position of B on A at distance Dist through the angle Angle is found through the following two equations:

B.X = A.X + cos(A.Angle + Angle) * Dist
B.Y = A.Y + sin(A.Angle + Angle) * Dist

Setting Angle equal to 180 would place object B "behind" object A assuming that the image for object A is facing to the right.
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,126

Post » Sun Aug 30, 2015 3:05 am

wow thanks alot! and by the way your other plugin is amazing but i didnt get to use it as I dont understand the whole ideas of cameras, thanks alot!
B
4
Posts: 27
Reputation: 254

Post » Sun Aug 30, 2015 5:40 am

what IS the sine and cosine anyway? I keep studying it but my mind cant apply the right triangle to the 0 through 360 degree spectrum even when its explained to me visually.

I was told to take sine as the opposite of the angle you have and cosine is the angle but add 90degrees to it? or is it the opposite + 90 degrees?
B
4
Posts: 27
Reputation: 254

Post » Sun Aug 30, 2015 6:49 am

When you know the degree and use it with cosine, you get the x-coordination on the unit circle (a circle with a radius of 1)
Using the degree with sine, you will get the y-coordination on the unit circle.

Let us put a dot on the unit circle with 30 degree.
Calculating cos(30) gives us 0.866
We can check this visually. Draw a vertical line from the dot and read the point where it cross the x-axis.

Same can be done for sine
Calculate sine(30) gives us 0.5
Check this visually by drawing a horizontal line from the dot. Read the point where this line cross the y-axis.

Try this for zero degree and 90 degree.
You will see cos(0)=1 and sin(90)=1 ,so cos(0)=sin(90)

Hopefully it helps!
It's time for me to return the favor :)
B
32
S
9
G
9
Posts: 132
Reputation: 5,370

Post » Sun Aug 30, 2015 3:23 pm

uhh hmmm I think I almost get it. I'm having trouble understanding what exactly cosine is but I'll double check some notes on trigonometry and cross reference until I do.
B
4
Posts: 27
Reputation: 254


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 27 guests