コード例 #1
0
ファイル: Rock.cs プロジェクト: AlyDrake/OpenCircuit
	public void OnCollisionEnter(Collision col) {
		float volume = col.impulse.magnitude *this.volume;
		if (volume > volumeThreshold) {
			source.volume = volume;
			if (source.clip == null)
				source.clip = clip;
			source.Play(0);
			LabelHandle audioLabel = new LabelHandle(transform.position, "rock");
			audioLabel.addTag(new Tag(TagEnum.Sound, volume));
			audioLabel.addTag(new Tag(TagEnum.Threat, 5f));
			AudioEvent rockCollisionSound = new AudioEvent(transform.position, audioLabel, transform.position);
			rockCollisionSound.broadcast(volume);

		}
	}
コード例 #2
0
    public void OnCollisionEnter(Collision col)
    {
        float volume = col.impulse.magnitude * this.volume;

        if (volume > volumeThreshold)
        {
            source.volume = volume;
            if (source.clip == null)
            {
                source.clip = clip;
            }
            source.Play(0);
            LabelHandle audioLabel = new LabelHandle(transform.position, "rock");
            audioLabel.addTag(new Tag(TagEnum.Sound, volume));
            audioLabel.addTag(new Tag(TagEnum.Threat, 5f));
            AudioEvent rockCollisionSound = new AudioEvent(transform.position, audioLabel, transform.position);
            rockCollisionSound.broadcast(volume);
        }
    }
コード例 #3
0
ファイル: Movement.cs プロジェクト: viviannimue/OpenCircuit
    void FixedUpdate()
    {
        // change collider height
        float desiredHeight = crouching? crouchHeight: normHeight;
        if (col.height < desiredHeight) {
            if (freeFallDelay == 0)
                setColliderHeight(col.height + climbRate /5);
            else
                setColliderHeight(col.height + climbRate);
            if (col.height > desiredHeight)
                setColliderHeight(desiredHeight);
        } else if (col.height > desiredHeight) {
            setColliderHeight(col.height - climbRate);
            if (col.height < desiredHeight)
                setColliderHeight(desiredHeight);
        }

        // update past forces
        int newForceCount = pastForces.Count -lastForceCount;
        pastForcesAddedCount.Add(newForceCount);
        if (pastForcesAddedCount.Count > pastForceCount) {
            int forcesToRemove = pastForcesAddedCount[0];
            pastForcesAddedCount.RemoveAt(0);
            pastForces.RemoveRange(0, forcesToRemove);
        }
        for (int i = 0; i < pastForces.Count; ++i)
            pastForces[i] *= 0.8f;
        lastForceCount = pastForces.Count;

        // move the player
        if (freeFallDelay < 0) {
            ++freeFallDelay;
            return;
        }
        if (!isGrounded()) {
            if (freeFallDelay > 0)
                --freeFallDelay;
            else {
                nextFootstep = 1;
                return;
            }
        } else
            freeFallDelay = 2;

        // get the move direction and speed
        if (!canMove) {
            rightSpeed = 0;
            forwardSpeed = 0;
        }
        desiredVel = new Vector3(rightSpeed, 0, forwardSpeed);
        float speed = desiredVel.magnitude * (sprinting ? calculateSprintMultiplier() : 1) *(crouching? crouchSpeedMultiplier: 1);
        desiredVel = myPlayer.cam.transform.TransformDirection(desiredVel);
        desiredVel.y = 0;
        desiredVel.Normalize();

        // move parallel to the ground
        if (isGrounded()) {
            Vector3 sideways = Vector3.Cross(Vector3.up, desiredVel);
            desiredVel = Vector3.Cross(sideways, groundNormal).normalized;
        }
        desiredVel *= speed;

        // slow down when moving up a slope
        if (desiredVel.y > 0)
            desiredVel *= 1 - Mathf.Pow(desiredVel.y / speed, 2);
        if (!isGrounded())
            desiredVel.y = GetComponent<Rigidbody>().velocity.y;

        // handle the maximum acceleration
        Vector3 force = desiredVel -GetComponent<Rigidbody>().velocity +groundSpeed;
        float maxAccel = Mathf.Min(Mathf.Max(acceleration *force.magnitude, acceleration /3), acceleration *2);
        if (force.magnitude > maxAccel) {
            force.Normalize();
            force *= maxAccel;
        }
        GetComponent<Rigidbody>().AddForce(force, ForceMode.VelocityChange);

        // play footstep sounds
        float currentSpeed = GetComponent<Rigidbody>().velocity.sqrMagnitude;
        if (nextFootstep <= Time.fixedTime && currentSpeed > 0.1f) {
            if (nextFootstep != 0) {
                float volume = 0.8f -(0.8f / (1 + currentSpeed /100));
                playFootstep(volume);
                AudioEvent footStepsEvent = new AudioEvent(transform.position, new Tag(TagEnum.Threat, 5f));
                footStepsEvent.broadcast(volume);
            }
            nextFootstep = Time.fixedTime + minimumFoostepOccurence / (1 + currentSpeed * foostepSpeedScale);
        }
        if (desiredVel.sqrMagnitude == 0 && currentSpeed < 1f && nextFootstep != 0) {
            float volume = 0.1f * currentSpeed;
            playFootstep(volume);
            nextFootstep = 0;
        }

        // update sprinting
        if (desiredVel.sqrMagnitude > 0.1f && sprinting) {
            if (myPlayer.oxygen < oxygenStopSprint)
                myPlayer.oxygen -= myPlayer.oxygenRecoveryRate *Time.deltaTime;
            else if (crouching)
                sprinting = false;
            else
                myPlayer.oxygen -= oxygenSprintUsage * Time.deltaTime;
        }

        // THE NEW STEP SYSTEM!!!
        //climb();

        // check for no more floor, in case it was deleted
        //if (floor == null)
            groundNormal = Vector3.zero;
    }
コード例 #4
0
ファイル: Movement.cs プロジェクト: Michaud1336/OpenCircuit
    void FixedUpdate()
    {
        // change collider height
        float desiredHeight = crouching? crouchHeight: normHeight;

        if (col.height < desiredHeight)
        {
            if (freeFallDelay == 0)
            {
                setColliderHeight(col.height + climbRate / 5);
            }
            else
            {
                setColliderHeight(col.height + climbRate);
            }
            if (col.height > desiredHeight)
            {
                setColliderHeight(desiredHeight);
            }
        }
        else if (col.height > desiredHeight)
        {
            setColliderHeight(col.height - climbRate);
            if (col.height < desiredHeight)
            {
                setColliderHeight(desiredHeight);
            }
        }

        // update past forces
        int newForceCount = pastForces.Count - lastForceCount;

        pastForcesAddedCount.Add(newForceCount);
        if (pastForcesAddedCount.Count > pastForceCount)
        {
            int forcesToRemove = pastForcesAddedCount[0];
            pastForcesAddedCount.RemoveAt(0);
            pastForces.RemoveRange(0, forcesToRemove);
        }
        for (int i = 0; i < pastForces.Count; ++i)
        {
            pastForces[i] *= 0.8f;
        }
        lastForceCount = pastForces.Count;

        // move the player
        if (freeFallDelay < 0)
        {
            ++freeFallDelay;
            return;
        }
        if (!isGrounded())
        {
            if (freeFallDelay > 0)
            {
                --freeFallDelay;
            }
            else
            {
                nextFootstep = 1;
                return;
            }
        }
        else
        {
            freeFallDelay = 2;
        }

        // get the move direction and speed
        if (!canMove)
        {
            rightSpeed   = 0;
            forwardSpeed = 0;
        }
        desiredVel = new Vector3(rightSpeed, 0, forwardSpeed);
        float speed = desiredVel.magnitude * (sprinting ? calculateSprintMultiplier() : 1) * (crouching? crouchSpeedMultiplier: 1);

        desiredVel   = myPlayer.cam.transform.TransformDirection(desiredVel);
        desiredVel.y = 0;
        desiredVel.Normalize();

        // move parallel to the ground
        if (isGrounded())
        {
            Vector3 sideways = Vector3.Cross(Vector3.up, desiredVel);
            desiredVel = Vector3.Cross(sideways, groundNormal).normalized;
        }
        desiredVel *= speed;

        // slow down when moving up a slope
        if (desiredVel.y > 0)
        {
            desiredVel *= 1 - Mathf.Pow(desiredVel.y / speed, 2);
        }
        if (!isGrounded())
        {
            desiredVel.y = GetComponent <Rigidbody>().velocity.y;
        }

        // handle the maximum acceleration
        Vector3 force    = desiredVel - GetComponent <Rigidbody>().velocity + groundSpeed;
        float   maxAccel = Mathf.Min(Mathf.Max(acceleration * force.magnitude, acceleration / 3), acceleration * 2);

        if (force.magnitude > maxAccel)
        {
            force.Normalize();
            force *= maxAccel;
        }
        GetComponent <Rigidbody>().AddForce(force, ForceMode.VelocityChange);

        // play footstep sounds
        float currentSpeed = GetComponent <Rigidbody>().velocity.sqrMagnitude;

        if (nextFootstep <= Time.fixedTime && currentSpeed > 0.1f)
        {
            if (nextFootstep != 0)
            {
                float volume = 0.8f - (0.8f / (1 + currentSpeed / 100));
                playFootstep(volume);
                LabelHandle audioLabel = new LabelHandle(transform.position, "footsteps");
                audioLabel.addTag(new Tag(TagEnum.Sound, volume));
                audioLabel.addTag(new Tag(TagEnum.Threat, 5f));
                AudioEvent footStepsEvent = new AudioEvent(transform.position, audioLabel, transform.position);
                footStepsEvent.broadcast(volume);
            }
            nextFootstep = Time.fixedTime + minimumFoostepOccurence / (1 + currentSpeed * foostepSpeedScale);
        }
        if (desiredVel.sqrMagnitude == 0 && currentSpeed < 1f && nextFootstep != 0)
        {
            float volume = 0.1f * currentSpeed;
            playFootstep(volume);
            nextFootstep = 0;
        }


        // update sprinting
        if (desiredVel.sqrMagnitude > 0.1f && sprinting)
        {
            if (myPlayer.oxygen < oxygenStopSprint)
            {
                myPlayer.oxygen -= myPlayer.oxygenRecoveryRate * Time.deltaTime;
            }
            else if (crouching)
            {
                sprinting = false;
            }
            else
            {
                myPlayer.oxygen -= oxygenSprintUsage * Time.deltaTime;
            }
        }



        // THE NEW STEP SYSTEM!!!
        //climb();


        // check for no more floor, in case it was deleted
        //if (floor == null)
        groundNormal = Vector3.zero;
    }