Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class pushPlayer : MonoBehaviour {
- public float gravity = 300.0F; // HOW MUCH GRAVITY IS APPLIED?
- public int _dirGravity = 0; // WHICH WAY IS GRAVITY FACING?
- public float speedRotation = 2F; // HOW FAST CAN WE ROTATE THE CHARACTER?
- public bool isGrounded = false; // ARE WE ON A SURFACE?
- public float jumpSpeed = 300.0F; // HOW HIGH CAN WE JUMP?
- void FixedUpdate() {
- // CHANGE THE GRAVITY DIRECTION WITH KEYS
- if(Input.GetKeyDown(KeyCode.Q))
- _dirGravity--;
- if(Input.GetKeyDown(KeyCode.E))
- _dirGravity++;
- if(_dirGravity > 5)
- _dirGravity = 0;
- else if(_dirGravity < 0)
- _dirGravity = 5;
- // DIRECTION OF GRAVITY
- switch(_dirGravity) {
- case 0: // DOWN
- gravity = -500;
- Physics.gravity = new Vector3(0.0F,gravity * Time.deltaTime,0.0F);
- transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0.0F,0.0F,0.0F), Time.deltaTime * speedRotation);
- break;
- case 1: // UP
- gravity = 500;
- Physics.gravity = new Vector3(0.0F,gravity * Time.deltaTime,0.0F);
- transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0.0F,0.0F,180.0F), Time.deltaTime * speedRotation);
- break;
- case 2: // RIGHT
- gravity = -500;
- Physics.gravity = new Vector3(gravity * Time.deltaTime,0.0F,0.0F);
- transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0.0F,0.0F,270.0F), Time.deltaTime * speedRotation);
- break;
- case 3: // LEFT
- gravity = 500;
- Physics.gravity = new Vector3(gravity * Time.deltaTime,0.0F,0.0F);
- transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0.0F,0.0F,90.0F), Time.deltaTime * speedRotation);
- break;
- case 4: // BACKWARD
- gravity = -500;
- Physics.gravity = new Vector3(0.0F,0.0F,gravity * Time.deltaTime);
- transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(90.0F,0.0F,0.0F), Time.deltaTime * speedRotation);
- break;
- case 5: // FORWARD
- gravity = 500;
- Physics.gravity = new Vector3(0.0F,0.0F,gravity * Time.deltaTime);
- transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(270.0F,0.0F,0.0F), Time.deltaTime * speedRotation);
- break;
- }
- // WHEN PLAYER NOT TOUCHING SURFACE
- if (!isGrounded){
- Vector3 dwn = transform.TransformDirection(Vector3.down);
- if (Physics.Raycast(transform.position, dwn, 0.5F)) {
- isGrounded = true;
- }
- }
- // WHEN PLAYER is TOUCHING SURFACE
- else {
- if(Input.GetButtonDown("Jump")) {
- // JUMP DEPENDING ON GRAVITY
- switch(_dirGravity) {
- case 0: // DOWN
- rigidbody.AddForce(Vector3.up * jumpSpeed);
- break;
- case 1: // UP
- rigidbody.AddForce(Vector3.down * jumpSpeed);
- break;
- case 2: // LEFT
- rigidbody.AddForce(Vector3.right * jumpSpeed);
- break;
- case 3: // RIGHT
- rigidbody.AddForce(Vector3.left * jumpSpeed);
- break;
- case 4: // BACKWARD
- rigidbody.AddForce(Vector3.forward * jumpSpeed);
- break;
- case 5: // FORWARD
- rigidbody.AddForce(Vector3.back * jumpSpeed);
- break;
- }
- isGrounded = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement