Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using MoreMountains.NiceVibrations;
- //using XInputDotNetPure;
- public class Damage : MonoBehaviour
- {
- public Rigidbody rb;
- public WheelCollider[] wheel;
- float speed;
- float combine;
- JointSpring ss;
- public AudioSource audio;
- public AudioClip ac;
- public ParticleSystem sparks;
- public short sparkCount;
- //PlayerIndex playerIndex;
- //GamePadState state;
- //GamePadState prevState;
- public bool grounded = false;
- public bool ramp = false;
- //public Material materialColor;
- float initialMass;
- public GameObject p;
- public Color newColor;
- public Material mat;
- float initTorque;
- float initMaxSpeed;
- public float stabilizeSpeed;
- Vector3 test;
- void Start()
- {
- ss = wheel[0].suspensionSpring;
- initialMass = rb.mass;
- adjust();
- FindObjectOfType<GameManager>().Mass(rb.mass);
- for (int i = 0; i < wheel.Length; i++)
- {
- wheel[i].ConfigureVehicleSubsteps(500, 1200, 1500);
- }
- }
- void Update()
- {
- for (int i = 0; i < wheel.Length; i++)
- {
- if (wheel[i].isGrounded == false)
- {
- grounded = false;
- ramp = false;
- // rb.constraints = RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
- //transform.rotation = Quaternion.LerpUnclamped(transform.rotation, Quaternion.Euler(transform.eulerAngles.x,0,0), Time.deltaTime * stabilizeSpeed);
- transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(transform.eulerAngles.x, 0, 0), Time.deltaTime);
- // transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(transform.rotation.x, 0, 0), Time.deltaTime * stabilizeSpeed);
- //var angles = transform.eulerAngles;
- //angles.y = Mathf.MoveTowardsAngle(angles.y, 0, stabilizeSpeed * Time.deltaTime);
- //angles.z = Mathf.MoveTowardsAngle(angles.z, 0, stabilizeSpeed * Time.deltaTime);
- //transform.eulerAngles = angles;
- }
- if (grounded == false)
- {
- if (wheel[i].isGrounded == true)
- {
- grounded = true;
- if (wheel[i].GetGroundHit(out WheelHit hit))
- {
- if (hit.collider.transform.gameObject.CompareTag("Ramp"))
- {
- print("yo");
- ramp = true;
- }
- }
- else
- {
- ramp = false;
- }
- }
- }
- }
- if (grounded == true)
- {
- FindObjectOfType<GameManager>().s = rb.position.z;
- }
- }
- private void OnCollisionEnter(Collision col)
- {
- combine = Mathf.Abs(col.impactForceSum.x) + Mathf.Abs(col.impactForceSum.y) + Mathf.Abs(col.impactForceSum.z); replace
- //print("combine: " + combine);
- if (rb.mass / ( 1 + (combine/1000) ) > 10)
- {
- rb.mass = rb.mass / (1 + (combine/1000) );
- }
- else
- {
- rb.mass = 10;
- }
- adjust();
- //AndroidManager.HapticFeedback();
- FindObjectOfType<GameManager>().Mass(rb.mass);
- audio.PlayOneShot(ac,combine/200);
- MMVibrationManager.TransientHaptic(combine / 200,0.1f,true,this);
- sparkCount = (short)(combine/8);
- Instantiate(sparks, col.contacts[0].point, Quaternion.identity);
- print(combine/200);
- //MMVibrationManager.Haptic(HapticTypes.MediumImpact,false,false,this);
- //audio.pitch = Random.Range(0.8f, 1.2f);
- //Handheld.Vibrate();
- //StartCoroutine(Vibrate());
- }
- void adjust()
- {
- FindObjectOfType<AllWheelDrive>().torque = 12 * rb.mass * FindObjectOfType<GameManager>().speedMultiplier;
- ss.spring = 200 * rb.mass;
- ss.damper = 4 * rb.mass;
- for (int i = 0; i < wheel.Length; i++)
- {
- wheel[i].suspensionSpring = ss;
- wheel[i].mass = 0.01f * rb.mass;
- //mesh = p.GetComponent<MeshRenderer>();
- }
- newColor = new Color((initialMass - rb.mass) / initialMass, rb.mass / initialMass, 0);
- mat.color = newColor;
- }
- //IEnumerator Vibrate()
- //{
- // GamePad.SetVibration(playerIndex, combine / 100, combine / 100);
- // yield return new WaitForSeconds(0.1f);
- // GamePad.SetVibration(playerIndex, 0, 0);
- //}
- }
Advertisement
Add Comment
Please, Sign In to add comment