- Home /
Move player in a circular manner
Hi!
i'm creating a pong game for learning purpose and decided to have the Paddle moving freely but with a slight change in its control.
When pressing LEFT OR RIGHT it should move in polar coordinates facing the ball. And UP OR DOWN moves the paddle towards or backwards the ball.
[2]: https://imgur.com/RMvJmES
var ball = Vector3.zero;
var d = ball - translation.Value.ToVector3();
var radius = d.magnitude;
var dir = d.normalized * data.speed * deltaTime;
var angle = Vector3.Angle(ball, translation.Value);
var nextPos = translation.Value;
if (data.direction.x > 0)
{
nextPos.x += dir.x + 15 * math.sin(angle) * data.speed * deltaTime;
nextPos.z += dir.z + 15 * math.cos(angle) * data.speed * deltaTime;
}
if (data.direction.x < 0)
{
nextPos.x -= dir.x + 15 * math.sin(angle) * data.speed * deltaTime;
nextPos.z -= dir.z + 15 * math.cos(angle) * data.speed * deltaTime;
}
translation.Value = nextPos;
Comment