コード例 #1
0
    void AttachToVehicle(BaseVehicleClass vehicle)
    {
        vehicleAttachedTo = vehicle;
        //transform.parent = vehicleAttachedTo.transform;
        vehicleAttachedTo.AddZombieOnRoof(gameObject);
        GetComponent <SeekPlayer>().enabled = false;
        if (GetComponent <DieWhenHitByVehicle>())
        {
            GetComponent <DieWhenHitByVehicle>().enabled = false;
        }
        rb.constraints |= RigidbodyConstraints.FreezePosition;
        Physics.IgnoreCollision(vehicleAttachedTo.GetComponent <Collider>(), GetComponent <ChangeColliderOnDeath>().aliveCollider);
        climbing            = true;
        climbingPercentDone = 0;

        vehicleRigidbody        = vehicleAttachedTo.GetComponent <Rigidbody>();
        localStartClimbPosition = vehicleAttachedTo.transform.InverseTransformPoint(transform.position);
        localEndClimbPosition   = localStartClimbPosition;
        localEndClimbPosition.y = 5.0f;
        localEndPosition        = localEndClimbPosition * 0.5f;//towards centre of vehicle
        localEndPosition.y      = localEndClimbPosition.y;
        //set end pos to point actually touching top of vehicle
        localEndPosition        = vehicleAttachedTo.transform.InverseTransformPoint(vehicleRigidbody.ClosestPointOnBounds(vehicleAttachedTo.transform.TransformPoint(localEndPosition)));
        localEndClimbPosition.y = localEndPosition.y;
    }
コード例 #2
0
    void Update()
    {
        if (vehicleAttachedTo != null)
        {
            if (climbing)
            {
                float   percentageOfClimbingTimeSpentOnSide = 0.7f;
                float   lerp;
                Vector3 start, end;
                if (climbingPercentDone <= percentageOfClimbingTimeSpentOnSide)
                {
                    lerp  = climbingPercentDone / percentageOfClimbingTimeSpentOnSide;
                    start = localStartClimbPosition;
                    end   = localEndClimbPosition;
                }
                else
                {
                    lerp  = (climbingPercentDone - percentageOfClimbingTimeSpentOnSide) / (1.0f - percentageOfClimbingTimeSpentOnSide);
                    start = localEndClimbPosition;
                    end   = localEndPosition;
                }
                Vector3 localTargetPos = Vector3.Lerp(start, end, lerp);
                transform.position = vehicleAttachedTo.transform.TransformPoint(localTargetPos);
                //SeekPlayer script is disabled so won't face vehicle
                Vector3 lookTowardsVehicle = vehicleAttachedTo.transform.position - transform.position;
                lookTowardsVehicle.y = 0;
                lookTowardsVehicle.Normalize();
                transform.rotation = Quaternion.LookRotation(lookTowardsVehicle);

                //Debug.DrawLine(vehicleAttachedTo.transform.TransformPoint(localStartClimbPosition), vehicleAttachedTo.transform.TransformPoint(localEndClimbPosition), Color.red);

                climbingPercentDone += climbingSpeed * Time.deltaTime;
                if (climbingPercentDone >= 1.0f)
                {
                    climbing         = false;
                    transform.parent = vehicleAttachedTo.transform;
                    Physics.IgnoreCollision(vehicleAttachedTo.GetComponent <Collider>(), GetComponent <ChangeColliderOnDeath>().aliveCollider, false);
                    rb.constraints &= ~RigidbodyConstraints.FreezePosition;
                }
            }
            else
            {
                transform.position += (vehicleAttachedTo.transform.TransformPoint(localEndPosition) - transform.position).normalized * 1.0f * Time.deltaTime;
                if (vehicleAttachedTo.GetDriver() == null)//driver has got out
                {
                    DetachFromVehicle();
                }
                if (transform.position.y - vehicleAttachedTo.transform.position.y < 1.0f)
                {
                    //No longer on roof after climbing
                    DetachFromVehicle();
                }
            }
            if (vehicleRigidbody && Vector3.Distance(transform.position, vehicleRigidbody.ClosestPointOnBounds(transform.position)) > 1.0f)
            {
                //Too far from vehicle
                DetachFromVehicle();
            }
        }
    }
コード例 #3
0
    private void TryEnterVehicle(BaseVehicleClass vehicle)
    {
        if (_occupyCooldown <= 0.0f && !_occupiedVehicle)
        {
            if (!Movement.InputLeft() && !Movement.InputRight())
            {
                if (vehicle.health <= 0 || vehicle.GetFuelPercentage() <= 0)
                {
                    return;
                }

                GameObject followCamera = gameObject.GetComponent <DisableVehicle>().followCamera;
                //if (followCamera == null) Debug.Log("null followcamera");
                //if (followCamera.GetComponent<FollowCamera>() == null) Debug.Log("null followcamera component");
                //if (followCamera.GetComponent<FollowCamera>().target == null) Debug.Log("null followcamera component target");
                //if (vehicle == null) Debug.Log("null vehicle");
                if (followCamera != null)
                {
                    followCamera.GetComponent <FollowCamera>().target = vehicle.gameObject;
                }

                gameObject.GetComponent <DisableVehicle>().followCamera = null;
                vehicle.GetComponent <DisableVehicle>().followCamera    = followCamera;
                vehicle.SetDriver(gameObject);

                EnterVehicle(vehicle);

                Camera.main.GetComponent <TransparentifyObject>().player = vehicle.transform;

                _occupiedVehicle = true;
            }
        }
    }
コード例 #4
0
    protected virtual void EnterVehicle(BaseVehicleClass vehicle)
    {
        Transform driverTransform = vehicle.transform.Find("DriverTransform");

        if (driverTransform == null)
        {
            gameObject.transform.Translate(0, 100, 0);
        }
        else
        {
            //place player on bike
            BikeLean bike = vehicle.GetComponent <BikeLean>();
            bike.enabled = true;
            gameObject.transform.parent        = driverTransform;
            gameObject.transform.localPosition = Vector3.zero;
            gameObject.transform.localRotation = Quaternion.identity;
        }
        GetComponent <Collider>().enabled = false;
        Rigidbody rb = GetComponent <Rigidbody>();

        rb.useGravity  = false;
        rb.constraints = RigidbodyConstraints.FreezeAll;
        gameObject.GetComponentInChildren <ZombieDetector>().enabled = false;        // disable players zombie detector to prevent player using weapons while in vehicle
    }