Angle to vector? (opposite of vectorToAngle)

What I want to do, is determine the x.y coordinate at a distance "d" from the center of an object relative to the rotation of that object. In other words, a function that persistently calculates x.y coordinate 64 pixels away relative to Object A facing angle.

In more concrete terms, Object B constrains to Object A's rotation 64 pixels away. Object A can rotate anywhere and Object B will always stay 64 pixels away from Object A at Object A's rotation.

It is important that Object A's rotation can be determined by some other value, so that Object A can freely rotate in any direction at any time, but Object B always stays 64 pixels away from Object A at Object A's rotation.

Example:

  • making an arrow with a sharp dangerous tip, where the shaft is Object A and the tip is Object B. Object A shoots forward at an angle, and Object B constrains to be at the top of the shaft as the arrow is moving. (I know how constrain, I just don't know how to find the vector position on an angle)

Ideas?

Best Answer

  • SocksSocks London, UK.Posts: 12,822
    edited March 2015 Accepted Answer

    That's probably one of the most confusing descriptions I've ever read of wanting to constrain two objects together so they both move and rotate as a single object ! :)

    Constrain actor B's x position to:
    64 * cos (actor A's rotation)+ actor A's position X

    Constrain actor B's y position to:
    64 * sin (actor A's rotation)+ actor A's position Y

    If you want to position actor B somewhere besides 0° relative to actor A, then you'd need to add an offset to the angle that cos and sin are operating on, which would look like this:

    64 * cos ((actor A's rotation)+offset) + actor A's position X
    64 * sin ((actor A's rotation)+offset) + actor A's position Y

    P.S 'angle to vector' wouldn't really mean anything, you can't derive anything from an angle other than the value of that angle relative to 0°, angle to vector is a little like being able to work out a calculation from a result.

Answers

Sign In or Register to comment.