Exemplo n.º 1
0
    /*
     * Note: This may need to be modified so that the offset is calculated from the center of mass
     * or 'collider.bounds.center'.
     */

    void Impulse()
    {
        Vector2 offset        = (Vector2)transform.position - center.GetGlobalCenter();
        float   reversalValue = reversed ? -1 : 1;

        body.AddForce(-offset.normalized * reversalValue * gravity * Time.fixedDeltaTime * body.mass, ForceMode2D.Impulse);
    }
Exemplo n.º 2
0
    void ApplyCentripetalForce()
    {
        Vector2 offset = (Vector2)transform.position - center.GetGlobalCenter();                //the vector from the center of the planet to the player
        //Quaternion rotationOfOffset = Quaternion.FromToRotation(Vector3.up, offset);	//rotation of the offset vector from vertical
        //Vector2 tangent = rotationOfOffset * Vector3.right;		//the vector perpendicular to the offset vector in the xy plane
        //Vector2 projVelocity = Vector3.Project(body.velocity, tangent);	//the player's tangential velocity

        Vector2 projVelocity = Radium.TangentVelocity(transform.position, body, center.GetGlobalCenter());

        //print("Player velocity vector:" + projVelocity + " speed:" + projVelocity.magnitude);

        if (projVelocity.magnitude > Mathf.Epsilon)
        {
            Vector2 force = -offset.normalized * Time.fixedDeltaTime * projVelocity.sqrMagnitude * body.mass / offset.magnitude;
            body.AddForce(force, ForceMode2D.Impulse);
        }
    }
Exemplo n.º 3
0
    //takes the force that the player would like to exert (for movement) and limits it so the player doesn't go too fast
    Vector2 SpeedLimitedForce(Vector2 rawForce)
    {
        Vector2 projVelocity = Radium.TangentVelocity(transform.position, body, center.GetGlobalCenter());
        float   dot          = Vector2.Dot(rawForce, projVelocity);

        if (dot < 0)
        {
            return(rawForce);                   //if your applied force is against the current velocity, you get full force
        }
        if (projVelocity.magnitude >= maxTangentialSpeed)
        {
            return(Vector2.zero);               //if you are already going full speed, you get no force
        }
        //otherwise, you get enough force to get you up to full speed or full force, whichever is less
        float maxAllowedForce = Mathf.Min(maxTangentialSpeed - projVelocity.magnitude, rawForce.magnitude);

        return(rawForce.normalized * maxAllowedForce);
    }
Exemplo n.º 4
0
    void FixRotation()
    {
        Vector2 offset = (Vector2)transform.position - center.GetGlobalCenter();

        transform.rotation = Quaternion.LookRotation(Vector3.forward, offset);
    }
Exemplo n.º 5
0
 //returns the vector from the center to the given node
 Vector2 VectorToNode(Vector2 nodePosition)
 {
     return(nodePosition - center.GetGlobalCenter());
 }