• Create Account

# alexsok90

Member Since 16 Jan 2013
Offline Last Active Jun 07 2013 05:47 AM

### In Topic: [2D Java Help] Need help with pong remake.[2D Java Help]

22 February 2013 - 04:19 AM

```public float XVel = 1.0f;

public void BallMove()
{
if (ball.X < 0 || ball.X > 420)
XVel *= -1;

ball.X += XVel;
}
```

### In Topic: Turret rotation

16 January 2013 - 06:46 AM

#deleted

### In Topic: Turret rotation

16 January 2013 - 05:52 AM

These values don't make any sense. Are you sure you are using Atan2 method? Also keep in mind that this code makes use of radian angles (not degrees). Or maybe your rotationSpeed value is too high. In my project it was like 0.02f (i was calling this method every update).

#EDIT You can also try replacing that "else if" with "if" only. Or swapping Atan2 arguments from "src - target" to "target - src".

### In Topic: Turret rotation

16 January 2013 - 05:27 AM

Ah, sorry - this topRotation should be currentRotation. I was renaming the variables and missed this one.

### In Topic: Turret rotation

16 January 2013 - 02:54 AM

Here is the code from tank game I developed. It rotates the turret clockwise or counter-clockwise (depeding on which path is shorter) with desired speed.

```destinationRotation = Math.Atan2(turret.Y - target.Y, turret.X - target.X) + Math.PI;

if (destinationRotation != currentRotation)
{
if (destinationRotation > currentRotation)
{
if (currentRotation < destinationRotation - Math.PI)
currentRotation -= rotationSpeed;
else
currentRotation += rotationSpeed;
}
else if (destinationRotation  < topRotation)
{
if (currentRotation > destinationRotation + Math.PI)
currentRotation += rotationSpeed;
else
currentRotation -= rotationSpeed;
}

if (currentRotation > Math.PI * 2.0f) currentRotation = 0;
if (currentRotation < 0) currentRotation = Math.PI * 2.0f;
}```

PARTNERS