Guest User

please help Q-Q

a guest
May 5th, 2020
91
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Player_controller : MonoBehaviour
  6. {
  7.  
  8.     Rigidbody rb;
  9.     CapsuleCollider caps;
  10.     GameObject bac;
  11.  
  12.     public float Resistence = 10;
  13.     public float velJump = 5;
  14.     public float Velocity = 100;
  15.     public Animator anim;
  16.     bool fallen = false;
  17.     bool run = false;
  18.     private float tempRot;
  19.  
  20.     void OnCollisionEnter(Collision col)
  21.     {
  22.       if (col.relativeVelocity.magnitude > Resistence)
  23.       {
  24.         caps.enabled = false;
  25.         rb.constraints = RigidbodyConstraints.None;
  26.         anim.SetBool("hit", true);
  27.         fallen = true;
  28.         run = false;
  29.       }
  30.     }
  31.  
  32.     void Start()
  33.     {
  34.       rb = GetComponent<Rigidbody>();
  35.       caps = GetComponent<CapsuleCollider>();
  36.     }
  37.  
  38.     void Update()
  39.     {
  40.  
  41.  
  42.  
  43.       if(Input.GetKeyDown(KeyCode.Space))
  44.       {
  45.         Salto();
  46.       }
  47.  
  48.  
  49.       if (!fallen)
  50.       {
  51.         if(Input.GetKey(KeyCode.W))
  52.         {
  53.           if(Input.GetKey(KeyCode.LeftShift))
  54.           {
  55.             Velocity = 300;
  56.           } else {
  57.             Velocity = 100;
  58.           }
  59.  
  60.           anim.SetBool("hit", false);
  61.           run = true;
  62.         } else {
  63.           anim.SetBool("hit", true);
  64.           run = false;
  65.         }
  66.         if(Input.GetKey(KeyCode.D))
  67.         {
  68.           var angles = transform.rotation.eulerAngles;
  69.           angles.y +=  5;
  70.           transform.rotation = Quaternion.Euler(angles);
  71.         }
  72.         if(Input.GetKey(KeyCode.A))
  73.         {
  74.           var angles = transform.rotation.eulerAngles;
  75.           angles.y +=  -5;
  76.           transform.rotation = Quaternion.Euler(angles);
  77.         }
  78.       }else{
  79.         if(Input.GetKey(KeyCode.E))
  80.         {
  81.           //THIS IS WAT I MADE FOR GET THE RAGDOLL UP, IGNORE
  82.           //transform.position = new Vector3(transform.position.x, 2, transform.position.z);
  83.           //transform.rotation = Quaternion.Euler(0, 0, -90);
  84.           //rb.constraints = RigidbodyConstraints.FreezeRotation;
  85.           //fallen = false;
  86.         }
  87.       }
  88.     }
  89.  
  90.     void FixedUpdate()
  91.     {
  92.       if(run)
  93.       {
  94.         rb.AddForce(new Vector3(transform.forward.x,0, transform.forward.z)*Velocity);
  95.       }
  96.  
  97.     }
  98.  
  99.     void Salto()
  100.     {
  101.       if (!fallen)
  102.       {
  103.         rb.AddForce(new Vector3(0,velJump*40,0),ForceMode.Impulse);
  104.       }
  105.     }
  106.  
  107.  
  108. }
RAW Paste Data Copied