Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
4.0 kB
7
Indexable
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace SkateGame
{

public class SkateLocomotion : MonoBehaviour
{
    
    
    private Rigidbody rigidBody;  
    private Vector3 velocity;
    private Vector3 relHeight;
    public bool isGrounded;
    public bool isGrinding; 
    private BoxCollider collider;
    private CapsuleCollider capcollider;
    public float rotationSpeed = 4;
    private float maxSpeed = 40.0f; 
    private float maxHeight = 40.0f; 
    
void Start()
    {
        rigidBody = gameObject.GetComponent<Rigidbody>(); 
        collider = gameObject.GetComponent<BoxCollider>();
        capcollider = gameObject.GetComponent<CapsuleCollider>();
        gameObject.tag = "Player";  
    }
void FixedUpdate() 
    {
        //Basic Movements
        if (Input.GetKey(KeyCode.Space) && isGrounded)
        {
            rigidBody.AddRelativeForce(0, 0, 350.0f, ForceMode.Impulse);
        }
        if (Input.GetKey(KeyCode.S) && isGrounded){
            rigidBody.AddRelativeForce(0, 100f, 0, ForceMode.Impulse);
        }
        if (Input.GetKey(KeyCode.W) && isGrounded ){
            rigidBody.AddRelativeForce(0, -100f, 0, ForceMode.Impulse);
        }
        if (Input.GetKey(KeyCode.LeftShift) && isGrounded){
            rigidBody.AddRelativeForce(0, -300f, 0, ForceMode.Impulse);
        }
        if (Input.GetKey(KeyCode.S) && !isGrounded){
            rigidBody.AddRelativeForce(0, 10f, 0, ForceMode.Impulse);
        }
        if (Input.GetKey(KeyCode.W) && !isGrounded ){
            rigidBody.AddRelativeForce(0, -10f, 0, ForceMode.Impulse);
        }
        //Rotations
        if (Input.GetKey(KeyCode.D) && isGrounded)
        {
            Quaternion turnRotation = Quaternion.Euler(0f, 0f, 1.0f);
            rigidBody.MoveRotation(rigidBody.rotation * turnRotation);
        } 
        if (Input.GetKey(KeyCode.A) && isGrounded)
        {
            Quaternion turnRotation = Quaternion.Euler(0f, 0f, -1.0f);
            rigidBody.MoveRotation(rigidBody.rotation * turnRotation);
        }
        if (Input.GetKey(KeyCode.E))
        {
            rigidBody.velocity = new Vector3(0,0,0); 
            Quaternion turnRotation = Quaternion.Euler(0.0f, 0.0f, 10.0f);
            rigidBody.MoveRotation(rigidBody.rotation * turnRotation); 
        }
        if (Input.GetKey(KeyCode.Q))
        {
            rigidBody.velocity = new Vector3(0,0,0); 
            Quaternion turnRotation = Quaternion.Euler(0f, 0f, -10.0f);
            rigidBody.MoveRotation(rigidBody.rotation * turnRotation); 
        }
        //Clamps speed at certain velocity, no infinite speeding
        if (rigidBody.velocity.magnitude > maxSpeed)
        {
            rigidBody.velocity = Vector3.ClampMagnitude(rigidBody.velocity, maxSpeed);
        }
        if (rigidBody.velocity.y > maxHeight)
        {
            rigidBody.velocity = Vector3.ClampMagnitude(rigidBody.velocity, maxHeight);
        }
        //states
        if (isGrinding)
        {
            Quaternion turnRotation = Quaternion.Euler(0f, 0f, -40f);
            rigidBody.velocity = new Vector3(0,0,-50f); 

        }
    }
void OnCollisionEnter(Collision collision)
    {
        if (collision.collider.tag == "Ground")
        {
            isGrounded = true; 
        }
    }

void OnCollisionExit(Collision collision)
    {
        if (collision.collider.tag == "Ground")
        {
            isGrounded = false; 
        }
    }   
void OnTriggerEnter(Collider collider)
    {
        //fix this VVV
       if (collider.tag == "Grindable")
        {
            isGrinding = true; 
        }
    }
IEnumerator DeathCoroutine(float someParameter)
    {
        yield return new WaitForSeconds(3);
        Application.LoadLevel(Application.loadedLevel); 
    }
void OnTriggerExit(Collider collider)
    {
        
        isGrinding = false;
    }
}
}