public void Awake()
        {
            this.m_Body = GetComponent <PhysXRigidBody>();

            this.m_NetworkPosition = new Vector3();
            this.m_NetworkRotation = new Quaternion();
        }
Example #2
0
    IEnumerator ResetVehicle(int teamId)
    {
        List <VehicleHealthManager> vehicles = FindObjectsOfType <VehicleHealthManager>().ToList();

        foreach (VehicleHealthManager vehicle in vehicles)
        {
            if (vehicle.teamId == teamId)
            {
                // Reset stats
                //vehicle.GetComponent<PhotonView>().RPC(nameof(VehicleHealthManager.ResetProperties), RpcTarget.AllViaServer);



                // Move to spawnpoint
                vehicle.GetComponent <InputDriver>().enabled = true;
                Transform spawnPoint;
                if (teamId > spawnPoints.Count)
                {
                    spawnPoint = spawnPoints[0];
                }
                else
                {
                    spawnPoint = spawnPoints[teamId - 1];
                }
                PhysXRigidBody rigidBody = vehicle.GetComponent <PhysXRigidBody>();
                rigidBody.position = spawnPoint.position;
                rigidBody.rotation = spawnPoint.rotation;

                vehicle.ResetProperties();

                // Add back damping on camera after move
                yield return(new WaitForSecondsRealtime(0.5f));
            }
        }
    }
Example #3
0
 void Start()
 {
     body          = GetComponent <PhysXRigidBody>();
     startPosition = body.position;
     startRotation = body.rotation;
     body.AddTorque(Random.onUnitSphere, ForceMode.Impulse);
 }
    public void SetupSimData(PhysXRigidBody attachedRigidBody, IntPtr wheelSimData, int wheelNum, uint vehicleId)
    {
        if (autoCalculateSpringStrength)
        {
            float sprungMass = PhysXLib.GetSuspensionSprungMass(suspension);
            suspensionSpringStrength = (Physics.gravity.magnitude * sprungMass) / (suspensionDistance * (1 - suspensionSpringTargetPosition));
        }

        this.wheelNum = wheelNum;

        this.attachedRigidBody = attachedRigidBody;

        Transform bodyParent = attachedRigidBody.transform;

        PhysXVec3 wheelCentrePos = new PhysXVec3(bodyParent.InverseTransformPoint(transform.TransformPoint(wheelCentre)));
        PhysXVec3 forceAppPos    = new PhysXVec3(bodyParent.InverseTransformPoint(transform.TransformPoint(wheelCentre + forceAppPoint)));

        PhysXLib.SetWheelSimForceAppPoint(wheelSimData, wheelNum, forceAppPos);
        PhysXLib.SetWheelSimWheelCentre(wheelSimData, wheelNum, wheelCentrePos);
        PhysXLib.SetWheelSimWheelData(wheelSimData, wheelNum, wheel);
        PhysXLib.SetWheelSimTireData(wheelSimData, wheelNum, tire);
        PhysXLib.SetWheelSimSuspensionData(wheelSimData, wheelNum, suspension, new PhysXVec3(-transform.up));
        PhysXLib.SetWheelSimWheelShape(wheelSimData, wheelNum, -1);
        PhysXLib.SetWheelSimQueryFilterData(wheelSimData, wheelNum, 0, 0, 0, vehicleId);
    }
Example #5
0
    // Start is called before the first frame update.
    void Start()
    {
        myRb = GetComponent <PhysXRigidBody>();

        meshstateTracker = FindObjectOfType <MeshstateTracker>();

        deformableMeshes = new List <DeformableMesh>(GetComponentsInChildren <DeformableMesh>());
        DeformableMesh.Subdivide(deformableMeshes[0].maxEdgeLength, deformableMeshes[0].GetMeshFilter().mesh);
        vertices = new List <Vector3>(deformableMeshes[0].GetMeshFilter().mesh.vertices);

        //  Group similar vertices.
        meshGraph = meshstateTracker.GetMyMeshGraph(meshType);

        originalMesh          = Instantiate(deformableMeshes[0].GetMeshFilter().mesh);
        collisionResolver     = Instantiate(collisionResolver);
        resolverBody          = collisionResolver.GetComponent <PhysXBody>();
        resolverBody.position = new Vector3(0, 10000, 0);

        interfaceCar = GetComponent <InterfaceCarDrive4W>();
        if (interfaceCar != null)
        {
            frWheel            = interfaceCar.frontRightW;
            frWheelVertexGroup = NearestVertexTo(frWheel.transform.position);
            flWheel            = interfaceCar.frontLeftW;
            flWheelVertexGroup = NearestVertexTo(flWheel.transform.position);
            rrWheel            = interfaceCar.rearRightW;
            rrWheelVertexGroup = NearestVertexTo(rrWheel.transform.position);
            rlWheel            = interfaceCar.rearLeftW;
            rlWheelVertexGroup = NearestVertexTo(rlWheel.transform.position);
        }

        teamId = GetComponent <NetworkPlayerVehicle>().teamId;
    }
    private void Start()
    {
        //  Debug.LogWarning("Driver Crash Detector has not been ported to the new PhysX system");
        // return;

        npv  = GetComponent <NetworkPlayerVehicle>();
        myRb = GetComponent <PhysXRigidBody>();
        currentSensorReport = new CurrentSensorReportStruct();
        currentSensorReport.lastCrashedPlayer = transform.root;
    }
Example #7
0
 void Awake()
 {
     // Debug.LogWarning("Pooled Object has not been ported to the new PhysX system");
     // return;
     if (GetComponent <PhysXRigidBody>() != null)
     {
         rb = GetComponent <PhysXRigidBody>();
     }
     if (GetComponentInChildren <TrailRenderer>() != null)
     {
         tr = GetComponentInChildren <TrailRenderer>();
     }
 }
Example #8
0
 public override void DeactivateAbility()
 {
     if (driverPhotonView.IsMine)
     {
         abilityPhotonView.RPC(nameof(nitro_RPC), RpcTarget.All, false);
         abilityActivated = false;
         PhysXRigidBody rb = driverPhotonView.GetComponent <PhysXRigidBody>();
         if (rb.transform.InverseTransformDirection(rb.velocity).z > interfaceCarDrive4W.maxSpeed)
         {
             Vector3 vel = rb.transform.InverseTransformDirection(rb.velocity);
             vel.z       = interfaceCarDrive4W.maxSpeed;
             rb.velocity = rb.transform.TransformDirection(vel);
         }
     }
 }
    void CalculateTimeToHit(PhysXRigidBody otherPlayer)
    {
        // Debug.Log("Start calculateTimetoHit physx");
        float   answer   = Mathf.Infinity;
        Vector3 otherVel = transform.InverseTransformDirection(otherPlayer.velocity);

        Vector3 velocityDifference = localVel - otherVel;



        if (velocityDifference.z <= 1)
        {
            float relativeDistance = Vector3.Distance(otherPlayer.position, transform.position + transform.forward * frontSensorPosition.z);



            if (relativeDistance < 2)
            {
                distList.Add(relativeDistance);
                timeList.Add(0.05f);
            }
        }
        else if (velocityDifference.z > 1)
        {
            float relativeSpeed    = currentSpeed = velocityDifference.z;
            float relativeDistance = Vector3.Distance(otherPlayer.position, transform.position + transform.forward * frontSensorPosition.z);



            answer = relativeDistance / relativeSpeed;
            if (relativeDistance < 2)
            {
                answer = 0;
            }

            //  Debug.Log("Velocity difference player" + velocityDifference);
            //  Debug.Log("Velocity difference estimated time player" + answer + " and velocity differnce was " + velocityDifference);

            distList.Add(relativeDistance);
            timeList.Add(answer);

            // Debug.Log("End calculateTimetoHit physx velocityDifference.z > 1 ");
        }

        // Debug.Log("End calculateTimetoHit physx");
    }
    protected new void Start()
    {
        baseCollisionResistance = deathForce / maxHealth;
        myRb = GetComponent <PhysXRigidBody>();
        if (GetComponent <HotPotatoManager>() != null)
        {
            hasHotPotatoManager = true;
            hotPotatoManager    = GetComponent <HotPotatoManager>();
            collisionNpv        = GetComponent <NetworkPlayerVehicle>();
            if (collisionNpv != null && !collisionNpv.botDriver)
            {
                driverCrashDetector = GetComponent <DriverCrashDetector>();
            }
        }

        base.Start();
    }
Example #11
0
    public void SetupVehicleManager()
    {
        //   Debug.LogWarning("Vehicle Health Manager has not been fully ported to the new PhysX system");
        gamestateTracker           = FindObjectOfType <GamestateTracker>();
        gamestateTrackerPhotonView = gamestateTracker.GetComponent <PhotonView>();
        networkManager             = FindObjectOfType <NetworkManager>();
        maxHealth        = health;
        rb               = GetComponent <PhysXRigidBody>();
        icd              = GetComponent <InterfaceCarDrive>();
        icd4             = GetComponent <InterfaceCarDrive4W>();
        carDriver        = icd.GetComponent <IDrivable>();
        inputDriver      = GetComponent <InputDriver>();
        myPhotonView     = GetComponent <PhotonView>();
        npv              = GetComponent <NetworkPlayerVehicle>();
        announcerManager = FindObjectOfType <AnnouncerManager>();



        _rammingDetails = new Weapon.WeaponDamageDetails(null, 0, 0, Weapon.DamageType.ramming, 0, Vector3.zero);

        for (int i = 0; i < collisionAreas.Count; i++)
        {
            CollisionArea collisionArea = collisionAreas[i];
            collisionArea.rotation.eulerAngles = collisionArea.rotationEuler;
            collisionAreas[i] = collisionArea;
        }

        defaultDrag            = rb.linearDamping;
        defaultAngularDrag     = rb.angularDamping;
        playerTransformTracker = FindObjectOfType <PlayerTransformTracker>();

        PlayerEntry player = gamestateTracker.players.Get((short)PhotonNetwork.LocalPlayer.ActorNumber);

        if (player.teamId == teamId)
        {
            tutorials.SetActive(true);
        }
        else
        {
            tutorials.SetActive(false);
        }
        player.Release();
    }
Example #12
0
    private void Awake()
    {
        // Debug.LogWarning("AI control needs porting to new PhysX system.");
        //     return;
        // get the car controller reference

        myRb = GetComponent <PhysXRigidBody>();
        interfaceCarDrive = GetComponent <InterfaceCarDrive4W>();

        // give the random perlin a random value
        m_RandomPerlin = Random.value * 100;

        m_Rigidbody = GetComponent <Rigidbody>();

        CarDriver = interfaceCarDrive.GetComponent <IDrivable>();
        m_Driving = true;
        WaypointCircuit wpc = FindObjectOfType <WaypointCircuit>();

        if (wpc != null)
        {
            circuitFound = true;
        }
    }
Example #13
0
    IEnumerator CrashIntoTarget()
    {
        //Debug.Log("CrashIntoTarget");
        Transform      me       = interfaceCarDrive4W.transform;
        PhysXRigidBody rb       = me.GetComponentInParent <PhysXRigidBody>();
        PhysXRigidBody targetRb = target.GetComponent <PhysXRigidBody>();

        float elapsedTime = 0f;
        // rb.AddForce(transform.root.forward * rammingSpeed, ForceMode.VelocityChange);
        float fractionMaxSpeed = transform.root.InverseTransformDirection(rb.velocity).z / interfaceCarDrive4W.maxSpeed;

        while (elapsedTime <= duration && !justCollided)
        {
            float   estimatedTime = Vector3.Magnitude(target.position - transform.root.position) / rammingSpeed;
            Vector3 predictedPos  = target.position + targetRb.velocity * (estimatedTime);



            Vector3 movePos = Vector3.Lerp(target.position, predictedPos, elapsedTime / cooldown);

            Vector3 moveDir = movePos - rb.position;

            // if the predicted pos is out of our sight, then break
            if (Mathf.Abs(Vector3.Angle(transform.root.forward,
                                        target.position - transform.root.position)) > 50)
            {
                break;
            }
            // direction.Normalize ();


            /*
             *  float angle = Vector3.SignedAngle(transform.root.forward, predictedPos - transform.root.forward,
             *      transform.root.up);
             *
             *  Vector3 eulerAngleVelocity = new Vector3(0, angle, 0);
             *  Quaternion deltaRotation = Quaternion.Euler(eulerAngleVelocity);
             *  deltaRotation *= torque;*/



            if (Vector3.Distance(transform.root.position, target.position) > 5)
            {
                Vector3    direction  = movePos - transform.root.position;
                Quaternion toRotation = Quaternion.LookRotation(direction, Vector3.up);
                rb.rotation = Quaternion.RotateTowards(transform.root.rotation, toRotation, 10f * Time.deltaTime);


                Vector3 vel = moveDir.normalized *
                              (rammingSpeed * Mathf.Lerp(fractionMaxSpeed, 1, elapsedTime / cooldown));
                Vector3 relativeVel = transform.root.InverseTransformDirection(vel);
                relativeVel.y = -2;
                vel           = transform.root.TransformDirection(relativeVel);
                rb.velocity   = vel;
            }

            //  transform.root.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(direction),  Time.deltaTime * 3);
            // transform.root.transform.LookAt(direction);



            yield return(new WaitForFixedUpdate());

            elapsedTime += Time.deltaTime;
        }

        DeactivateAbility();
        justCollided = false;
    }
Example #14
0
 void Start()
 {
     rigidBody = GetComponentInParent <PhysXRigidBody>();
     collider  = GetComponent <PhysXCollider>();
 }
Example #15
0
 void Awake()
 {
     myRb         = GetComponent <PhysXRigidBody>();
     pooledObject = GetComponent <PooledObject>();
 }