Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Player_controller : MonoBehaviour
- {
- Rigidbody rb;
- CapsuleCollider caps;
- GameObject bac;
- public float Resistence = 10;
- public float velJump = 5;
- public float Velocity = 100;
- public Animator anim;
- bool fallen = false;
- bool run = false;
- private float tempRot;
- void OnCollisionEnter(Collision col)
- {
- if (col.relativeVelocity.magnitude > Resistence)
- {
- caps.enabled = false;
- rb.constraints = RigidbodyConstraints.None;
- anim.SetBool("hit", true);
- fallen = true;
- run = false;
- }
- }
- void Start()
- {
- rb = GetComponent<Rigidbody>();
- caps = GetComponent<CapsuleCollider>();
- }
- void Update()
- {
- if(Input.GetKeyDown(KeyCode.Space))
- {
- Salto();
- }
- if (!fallen)
- {
- if(Input.GetKey(KeyCode.W))
- {
- if(Input.GetKey(KeyCode.LeftShift))
- {
- Velocity = 300;
- } else {
- Velocity = 100;
- }
- anim.SetBool("hit", false);
- run = true;
- } else {
- anim.SetBool("hit", true);
- run = false;
- }
- if(Input.GetKey(KeyCode.D))
- {
- var angles = transform.rotation.eulerAngles;
- angles.y += 5;
- transform.rotation = Quaternion.Euler(angles);
- }
- if(Input.GetKey(KeyCode.A))
- {
- var angles = transform.rotation.eulerAngles;
- angles.y += -5;
- transform.rotation = Quaternion.Euler(angles);
- }
- }else{
- if(Input.GetKey(KeyCode.E))
- {
- //THIS IS WAT I MADE FOR GET THE RAGDOLL UP, IGNORE
- //transform.position = new Vector3(transform.position.x, 2, transform.position.z);
- //transform.rotation = Quaternion.Euler(0, 0, -90);
- //rb.constraints = RigidbodyConstraints.FreezeRotation;
- //fallen = false;
- }
- }
- }
- void FixedUpdate()
- {
- if(run)
- {
- rb.AddForce(new Vector3(transform.forward.x,0, transform.forward.z)*Velocity);
- }
- }
- void Salto()
- {
- if (!fallen)
- {
- rb.AddForce(new Vector3(0,velJump*40,0),ForceMode.Impulse);
- }
- }
- }
RAW Paste Data
Copied