x


Physics not initializing right away upon Play Testing in the editor

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!!!

more ▼

asked Apr 24 '12 at 08:09 PM

kburkhart84 gravatar image

kburkhart84
46 1 3

I just tested this through the build and run as well, and also ran it from outside of the editor, after the build. In both cases, and in the editor, it is about 9 seconds before the physics responds. But it isn't an input issue, because the shooting input works fine, right from the start.

Apr 25 '12 at 05:48 AM kburkhart84
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I finally stumbled upon a post in the Blender/External Tools Section of the forum here.

Basically, the model was doing the "default-take" animation from Blender, and the solution was to force it to not import animations, since my ship is a static model anyway. Suddenly, it responds instantly to physics like it should.

more ▼

answered May 04 '12 at 02:40 AM

kburkhart84 gravatar image

kburkhart84
46 1 3

:D Those "unwanted-animations-override-my-movement" problems are quite common ;) Good you figured it out ;)

May 04 '12 at 03:17 AM Bunny83
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1943
x67
x39
x2

asked: Apr 24 '12 at 08:09 PM

Seen: 436 times

Last Updated: May 04 '12 at 03:17 AM