Exemplo n.º 1
0
    public override void PostSceneInsertionSetup()
    {
        if (wheels.Count > 0)
        {
            IntPtr   wheelSimData   = PhysXLib.CreateWheelSimData(wheels.Count);
            IntPtr[] suspensions    = new IntPtr[wheels.Count];
            IntPtr   wheelPositions = PhysXLib.CreateVectorArray();

            for (int i = 0; i < wheels.Count; i++)
            {
                suspensions[i] = wheels[i].SetupInitialProperties();
                PhysXLib.AddVectorToArray(wheelPositions, new PhysXVec3(transform.InverseTransformPoint(wheels[i].worldWheelCentre)));
            }

            PhysXLib.SetSuspensionSprungMasses(suspensions, wheels.Count, wheelPositions, new PhysXVec3(Vector3.zero), mass);

            for (int i = 0; i < wheels.Count; i++)
            {
                //Debug.Log(vehicleId);
                wheels[i].SetupSimData(this, wheelSimData, i, vehicleId);
            }

            vehicle = PhysXLib.CreateVehicleFromRigidBody(physXBody, wheelSimData);

            for (int i = 0; i < wheels.Count; i++)
            {
                wheels[i].SetVehicle(vehicle);
            }
        }

        physXCOMPosition.FromVector(centreOfMass);
        // PhysXVec3 position = new PhysXVec3(centreOfMass);
        // PhysXQuat rotation = new PhysXQuat(Quaternion.identity);

        IntPtr oldCentre = PhysXLib.GetCentreOfMass(physXBody);

        IntPtr newCentre = PhysXLib.CreateTransform(physXCOMPosition, physXCOMRotation);

        PhysXLib.SetRigidBodyMassPose(physXBody, newCentre);

        if (vehicle != IntPtr.Zero)
        {
            PhysXLib.UpdateVehicleCentreOfMass(oldCentre, newCentre, vehicle);
        }

        if (GetComponentInChildren <CollisionSoftener>() != null)
        {
            Debug.Log("made ghost body");
            ghostBody     = PhysXLib.CreateGhostRigidBody(physXBody, ghostBlend);
            _ghostEnabled = true;
        }
    }