コード例 #1
0
//	public Vector2 GetMoveDirection (Vector3 center, Vector3 currentPosition, float distance, float speed)
//	{
//		Vector2 moveDirection = Vector2.zero;
//
//		// TODO Problem: speed zu hoch, keine Kreisbewegung (eckig)
//		// TODO currentAngle wieder über transform.Position und Center Position berechnen
//		// http://de.wikipedia.org/wiki/Kreiswinkel
//		// http://en.wikipedia.org/wiki/Inscribed_angle
//
//		orbitCurrentAnglePosition = CalculateAngle (currentPosition, center);
//		orbitCurrentAnglePosition -= speed;
//
//		Vector3 nextPosition = Vector3.zero;
//		// Mathf.Cos (f)
//		// Returns the cosine of angle f in radians.
//		nextPosition.x = Mathf.Cos (orbitCurrentAnglePosition);
//		// Returns the sine of angle f in radians.
//		nextPosition.y = Mathf.Sin (orbitCurrentAnglePosition);
//
////		nextPosition.Normalize();
//
//		nextPosition += center;
//
//		//
//		moveDirection = MoveDirection.ShortestPath (currentPosition, nextPosition);
//
//		return moveDirection;
//	}

    public Vector2 GetMoveDirection(Vector3 center, Vector3 currentPosition, float distance, float speed)
    {
        // transform.RotateAround
        // Rotates the transform about axis passing through point in world coordinates by angle degrees.
        transform.RotateAround(center, Vector3.forward, winkelGeschwindigkeit * Time.deltaTime);

        // eigene Rotation aufheben
        transform.rotation = Quaternion.identity;

        Vector3 nextPosition = transform.position;

        // Bewegungsrichtung berechnen
        moveDirection = MoveDirection.ShortestPath(currentPosition, nextPosition) * speed;

        // position zurücksetzen
        transform.position = currentPosition;
        return(moveDirection);
    }
コード例 #2
0
 public Vector2 GetMoveDirection(Vector3 currentPosition, Vector3 destination, float moveSpeed)
 {
     return(MoveDirection.ShortestPath(currentPosition, destination) * moveSpeed);
 }
コード例 #3
0
 public Vector2 GetMoveDirection(Vector3 currentPosition, Transform targetTransform, float moveSpeed)
 {
     return(MoveDirection.ShortestPath(currentPosition, targetTransform.position) * moveSpeed);
 }