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

0 favourites
  • 6 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • 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

    [quote:3kbqstwo]

    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.

    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:

  • 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.

  • 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!

  • 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?

  • 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!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)