Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class PhysicsManager : MonoBehaviour
- {
- float mass = 5f;
- float gravity = 9.8f;//(constante) m/s²
- public float drag = 0.95f; //Descontar do Thrust
- public Rigidbody rb; // só estamos usando a velocity por enquanto. Estamos fazendo o calc de gravity na mao
- public GameObject delta;//Trapezio
- public Respawner rpwn;
- [Header("Divisor relativo do Thurst")]
- public float boost = 0.098f; //divisor realtivo do Thurst (sim, isso é perCent) / 0.01f ~
- public Quaternion lift; //theta é o ponto w direção (ou um pivot veja o que fica mais eficaz)
- public float relativeThrust = 40;//e o impulso inicial
- public Vector3 debugRelative;
- public AudioSource strongWind;
- public AudioSource crashWing;
- public SteamVR_TrackedObject trackedObj;
- private void OnEnable()
- {
- rpwn = Object.FindObjectOfType<Respawner>();
- }
- public GameObject thrustAxis;
- public float speed;
- float Thrust()
- {
- thrustAxis.transform.position += thrustAxis.transform.forward * speed / 2;
- speed -= thrustAxis.transform.forward.y * 100f;//50.0f original
- if (speed < 0)
- speed = 500;
- relativeThrust = speed;
- return speed;
- }
- Vector3 RelativeDirection()
- {
- Vector3 fwd = lift * Vector3.forward;
- float relDirx = Mathf.Atan2(fwd.x, peso());
- float relDiry = Mathf.Atan2(fwd.y, peso());
- float relDirz = Mathf.Atan2(fwd.z, peso());
- Vector3 torque = new Vector3(relDirx, relDiry, relDirz);
- return torque;
- }
- //kilograma-forca ou N (Newton)
- float peso()
- {
- return mass * gravity;
- }
- float maxDistance = 100f;
- Vector3 tempVelocity;
- bool canMove;
- void Update()
- {
- CorrectFall();
- //Som temporario depois manda pra um mngr
- if (relativeThrust > 10000)
- strongWind.volume += 0.1f * Time.deltaTime;
- if (strongWind.volume > 0.8)
- strongWind.volume = 0.8f;
- if (Input.GetMouseButton(0))
- canMove = !canMove;
- }
- void FixedUpdate()
- {
- if (delta != null)
- lift = delta.transform.rotation;
- else
- return;
- rb.velocity = RelativeDirection() * Thrust();
- debugRelative = rb.velocity;
- }
- /// <summary>
- /// Condição para saída do terreno
- /// </summary>
- void CorrectFall()
- {
- if(Terrain.activeTerrain == true)
- {
- float terrainHeightWhereWeAre = Terrain.activeTerrain.SampleHeight(transform.position);
- if (terrainHeightWhereWeAre > transform.position.y)
- {
- transform.position = new Vector3(transform.position.x,
- terrainHeightWhereWeAre,
- transform.position.z);
- if (rpwn != null)
- rpwn.Continue();
- crashWing.Play();
- //EventManager.RespawnPlayer();
- }
- else
- {
- //Faça fitas
- }
- }
- }
- void OnTriggerStay(Collider other)
- {
- if(other.gameObject.tag == "Boundary")
- {
- if(rpwn != null)
- rpwn.Continue();
- }
- //HandleEventType();
- }
- public GameObject leaves;
- void OnTriggerEnter(Collider other)
- {
- if (other.tag == "tree")
- {
- leaves.SetActive(true);
- StartCoroutine(SpawnLeaves());
- }
- }
- IEnumerator SpawnLeaves()
- {
- yield return new WaitForSeconds(3f);
- leaves.SetActive(false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment