public override Vector2 UpdateLocation() { //FIXME: For efficiency store the last position and time and do relative calculations from last path used //FIXME: Get speed to work long curTime = (long)(Clock.getClock().getTime()); long relativeTime = curTime - StartTime; Vector2 addLocation = Vector2.Zero; Vector2 location = InitialLocation; LinkedListNode <Piece> curPiece = pieces.First; while (curPiece != null && curPiece.Value.duration < relativeTime) { addLocation = curPiece.Value.equation.GetLocation(curPiece.Value.duration); addLocation = VectorRotation.RotateVector(curPiece.Value.angleOffset, addLocation); location += addLocation; relativeTime -= (long)(curPiece.Value.duration); curPiece = curPiece.Next; } //Haven't reached the end else nothing will happen. if (curPiece != null) { addLocation = curPiece.Value.equation.GetLocation((long)(relativeTime)); addLocation = VectorRotation.RotateVector(curPiece.Value.angleOffset, addLocation); location += addLocation; // Console.WriteLine(location); } return(location); }
public void LaunchTowardsAngle(float initialSpeed, float direction) { active = true; trail.enabled = true; Vector2 directionVector = VectorRotation.RotateVector(Vector2.right, direction); Vector2 launchVelocity = (directionVector * initialSpeed); ballBody.velocity = launchVelocity; }
public void UpdateLaunchDirection() { targetLine.positionCount = 2; launchDirection = 90 + ((transform.position.x / 2) * -45); startLaunchLocation = new Vector2( transform.position.x * 1.25f, transform.position.y + 0.5f); targetLine.SetPosition(0, startLaunchLocation); Vector2 launchVector = VectorRotation.RotateVector(Vector2.right, launchDirection); int layerMask = LayerMask.GetMask("Bricks", "Balls"); RaycastHit2D hit = Physics2D.Raycast(transform.position, launchVector, 20, layerMask); if (hit.collider != null) { targetLaunchLocation = hit.point; } else { targetLaunchLocation = startLaunchLocation + (launchVector * 20); } targetLine.SetPosition(1, targetLaunchLocation); }