I’m designing a simple asteroids clone with Unity, in order to get to grips with it before I tackle bigger projects. I’ve created a ship object, that uses physics for the movement. I’ve been able to get the movement right, so I know in general the physics system is working fine. But, for some reason, when I click the play button to test things out, the physics doesn’t work for about 9 seconds. After that, it works fine, and I’m able to tweak public variables in my scripts.
The rest of the game seems to be working fine, making the ship shoot, and it doesn’t wait at all, since it doesn’t use a rigidbody, rather a sphere collider set as a trigger. Honestly, I don’t remember having this problem when I was testing the version right before the newest version. I’m using 3.5.1f2 at the moment, and before I was using 3.5.??, and I don’t remember the exact one. Here’s the code for the ship object. You can see it is actually pretty simple.
var turningDrag:float = 1;
var normalTurningDrag:float = 1;
var warpingDistancex:int = 42;
var warpingDistancez:int = 32;
var playerBullet:GameObject;
private var canShoot:boolean = true;
function Start ()
{
}
function FixedUpdate ()
{
//Turning
var turning = Input.GetAxis("Turn");
if(turning > 0.70)
{
rigidbody.angularDrag = turningDrag;
rigidbody.AddTorque(0, turningForce, 0);
}
else if(turning < -0.70)
{
rigidbody.angularDrag = turningDrag;
rigidbody.AddTorque(0, -1*turningForce, 0);
}
else
{
rigidbody.angularDrag = normalTurningDrag;
}
//Thrusting and Strafing
var thrusting = Input.GetAxis("Thrust");
var strafing = Input.GetAxis("Strafe");
if(thrusting!=0 || strafing!=0)
{
rigidbody.drag = thrustingDrag;
}
else
{
rigidbody.drag = normalDrag;
}
if(thrusting != 0)
{
rigidbody.AddRelativeForce(0, -1*thrusting*thrustingForce, 0);
}
if(strafing != 0)
{
rigidbody.AddRelativeForce(strafing*thrustingForce, 0, 0);
}
//Warping to other side
if(transform.position.x < -1*warpingDistancex)
transform.position.x = warpingDistancex;
if(transform.position.x > warpingDistancex)
transform.position.x = -1*warpingDistancex;
if(transform.position.z < -1*warpingDistancez)
transform.position.z = warpingDistancez;
if(transform.position.z > warpingDistancez)
transform.position.z = -1*warpingDistancez;
//Shooting
if(Input.GetAxis("Shoot"))
{
if(canShoot)
{
var bullet = Instantiate(playerBullet, transform.position, transform.rotation);
canShoot = false;
}
}
else
{
canShoot = true;
}
}
Remember, the shooting part works right away, but for some reason, the ships receiving the forces does not. At one point, I put a quick log output in one of the if statements there and it does output right away. Also, the physics doesn’t “add up” whatever is being done, rather it seems to ignore completely any forces until the about 9 seconds is up.
Any ideas?? Is there a setting I missed? I’m clueless at this point.
Thanks in advance!!!