Advertisement
Guest User

Untitled

a guest
May 11th, 2018
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.62 KB | None | 0 0
  1. using System.Collections;
  2.     using System.Collections.Generic;
  3.     using UnityEngine;
  4.    
  5.     public class PlayerControl : MonoBehaviour {
  6.         public GameObject CameraPivot;
  7.    
  8.    
  9.         public Vector3 Vellocity;
  10.    
  11.         public GameObject Player;
  12.    
  13.         public GameObject HookRight;
  14.         public GameObject RopeStartRight;
  15.         public GameObject DrillRight;
  16.         public Camera PlayerCamera;
  17.    
  18.         Transform TargetRight;
  19.         bool RightTargeted;
  20.         LineRenderer RightRope;
  21.         Vector3 StartPossition;
  22.         bool Collided = false;
  23.    
  24.         float RightRopeDistance = 0.0f;
  25.    
  26.         CharacterController CC;
  27.         void Start () {
  28.             CC = GetComponent<CharacterController>();
  29.             RightTargeted = false;
  30.             StartPossition = Player.transform.position;
  31.             RightRope = HookRight.GetComponent<LineRenderer>();
  32.             TargetRight = DrillRight.transform;
  33.         }
  34.         Vector2 Rotation = new Vector2(0,0);
  35.         // Update is called once per frame
  36.         void FixedUpdate () {
  37.             Vellocity = (Player.transform.position - StartPossition);
  38.             Vellocity = new Vector3(Vellocity.x / Time.fixedDeltaTime, Vellocity.y / Time.fixedDeltaTime, Vellocity.z / Time.fixedDeltaTime);
  39.             StartPossition = Player.transform.position;
  40.    
  41.             Rotation.x = Input.GetAxis ("Mouse X")*5;
  42.             Rotation.y = Input.GetAxis ("Mouse Y")*5;
  43.             transform.Rotate (0, Rotation.x , 0);
  44.             CameraPivot.transform.Rotate (Rotation.y, 0, 0);
  45.    
  46.            
  47.             if (Input.GetKey(KeyCode.W)) {
  48.                 Vellocity = Vellocity + new Vector3(Player.transform.forward.normalized.x * 10f * Time.fixedDeltaTime, Player.transform.forward.normalized.y * 10f * Time.fixedDeltaTime, Player.transform.forward.normalized.z * 10f * Time.fixedDeltaTime);
  49.             }
  50.             if (Input.GetKey(KeyCode.S)){
  51.                 Vellocity = Vellocity - new Vector3(Player.transform.forward.normalized.x * 10f * Time.fixedDeltaTime, Player.transform.forward.normalized.y * 10f * Time.fixedDeltaTime, Player.transform.forward.normalized.z * 10f * Time.fixedDeltaTime);
  52.             }
  53.             if (Input.GetKey(KeyCode.D))
  54.             {
  55.                 Vellocity = Vellocity + new Vector3(Player.transform.right.normalized.x * 10f * Time.fixedDeltaTime, Player.transform.right.normalized.y * 10f * Time.fixedDeltaTime, Player.transform.right.normalized.z * 10f * Time.fixedDeltaTime);
  56.             }
  57.             if (Input.GetKey (KeyCode.A)) {
  58.                 Vellocity = Vellocity - new Vector3(Player.transform.right.normalized.x * 10f * Time.fixedDeltaTime, Player.transform.right.normalized.y * 10f * Time.fixedDeltaTime, Player.transform.right.normalized.z * 10f * Time.fixedDeltaTime);
  59.             }
  60.    
  61.             if (Collided)
  62.             {
  63.                 Vellocity.y = 0;
  64.             }
  65.             else
  66.             {
  67.                 Vellocity.y = Vellocity.y - 16f * Time.fixedDeltaTime;
  68.             }
  69.    
  70.            
  71.            
  72.             Vellocity.x = Vellocity.x * 0.9f;
  73.             Vellocity.y = Vellocity.y * 0.9f;
  74.            
  75.             if (Vellocity.x > 10)
  76.             {
  77.                 Vellocity.x = 10;
  78.             }else if (Vellocity.x < -10)
  79.             {
  80.                 Vellocity.x = -10;
  81.             }
  82.    
  83.             if (Vellocity.y > 10)
  84.             {
  85.                 Vellocity.y = 10;
  86.             }else if (Vellocity.y < -10)
  87.             {
  88.                 Vellocity.y = -10;
  89.             }
  90.    
  91.             if (Vellocity.z > 10)
  92.             {
  93.                 Vellocity.z = 10;
  94.             }
  95.             else if (Vellocity.z < -10)
  96.             {
  97.                 Vellocity.z = -10;
  98.             }
  99.    
  100.             CC.Move(new Vector3(Vellocity.x * Time.fixedDeltaTime, Vellocity.y * Time.fixedDeltaTime, Vellocity.z * Time.fixedDeltaTime) );
  101.    
  102.             if (RightTargeted)
  103.             {
  104.    
  105.                 DrillRight.transform.SetPositionAndRotation(TargetRight.position, DrillRight.transform.rotation);
  106.                 if (Input.GetAxis("RightRopeFire") == 0)
  107.                 {
  108.                     RightTargeted = false;
  109.                     DrillRight.transform.position = RopeStartRight.transform.position;
  110.                     TargetRight = DrillRight.transform;
  111.                 }
  112.                 else if (Vector3.Distance(Player.transform.position, TargetRight.position) > RightRopeDistance)
  113.                 {
  114.                    
  115.                    
  116.                        
  117.                         /*Vector3 Temp = Player.transform.position - TargetRight.position;
  118.                         Temp.Normalize();
  119.                         Temp.Set(Temp.x * RightRopeDistance, Temp.y * RightRopeDistance, Temp.z * RightRopeDistance);
  120.    
  121.                         RaycastHit hit;
  122.                         if (Physics.Linecast(Player.transform.position, TargetRight.position + Temp, out hit))
  123.                         {
  124.                             Player.transform.SetPositionAndRotation(hit.transform.position, Quaternion.Euler(hit.normal));
  125.                             Debug.Log("Collided");
  126.                         }
  127.                         else
  128.                         {
  129.                             Player.transform.position = TargetRight.position + Temp;
  130.                         }
  131.                         */
  132.                         Vector3 Temp = Player.transform.position - TargetRight.position;
  133.                         Temp.Normalize();
  134.                         Temp.Set(Temp.x * RightRopeDistance, Temp.y * RightRopeDistance, Temp.z * RightRopeDistance);
  135.    
  136.                         CC.Move((Player.transform.position - TargetRight.position) - Temp);
  137.    
  138.                        
  139.    
  140.                         Player.transform.rotation = Quaternion.FromToRotation(Vector3.up, -Temp);
  141.                        
  142.    
  143.    
  144.                         //Vellocity = Player.transform.position - StartPossition;
  145.                    
  146.                 }
  147.    
  148.    
  149.             }
  150.             else
  151.             {
  152.                 Vector3 temp = new Vector3(RopeStartRight.transform.position.x, RopeStartRight.transform.position.y, RopeStartRight.transform.position.z);
  153.                 DrillRight.transform.SetPositionAndRotation(temp, RopeStartRight.transform.rotation);
  154.                 if (!(Input.GetAxis("RightRopeFire") == 0))
  155.                 {
  156.                     Vellocity = Vector3.zero;
  157.                     RaycastHit Hit;
  158.                     Vector3 Rot = PlayerCamera.transform.forward;
  159.    
  160.                     Vector3 RayOrigin = PlayerCamera.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0f));
  161.                     if (Physics.Raycast(RayOrigin, Rot, out Hit, 60))
  162.                     {
  163.                         RightTargeted = true;
  164.                         TargetRight.position = Hit.point;
  165.                         DrillRight.transform.SetPositionAndRotation(TargetRight.position, Quaternion.Euler(Rot));
  166.                         RightRopeDistance = Vector3.Distance(Player.transform.position, TargetRight.position);
  167.                     }
  168.                 }
  169.    
  170.             }
  171.             Vector3[] RightPossitions = new Vector3[2];
  172.             RightPossitions[0] = RopeStartRight.transform.position;
  173.             RightPossitions[1] = TargetRight.position;
  174.             RightRope.SetPositions(RightPossitions);
  175.    
  176.             Collided = false;
  177.    
  178.    
  179.    
  180.         }
  181.    
  182.         void OnCollisionStay(Collision collision)
  183.         {
  184.             Collided = true;
  185.             Debug.Log("True");
  186.         }
  187.         void OnCollisionExit(Collision collision)
  188.         {
  189.             Collided = false;
  190.         }
  191.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement