Advertisement
wa12rior

Skyhooks

Jan 30th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.06 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5.  
  6. public class GravityDetection : MonoBehaviour
  7. {
  8.     public float speed;
  9.     public GameObject obj;
  10.     public static bool inTrigger = false;
  11.    
  12.     private Vector3 zAxis = new Vector3(0, 0, 1);
  13.  
  14.     void FixedUpdate() {
  15.         if (obj && inTrigger) {
  16.             transform.RotateAround(obj.transform.position, zAxis, speed);
  17.         }
  18.     }
  19.  
  20.     void OnTriggerEnter2D(Collider2D other) {
  21.         if (other.gameObject.CompareTag("Gravity Field")) {
  22.             obj = other.gameObject;
  23.             inTrigger = true;
  24.         }
  25.     }
  26. }
  27.  
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using UnityEngine;
  31.  
  32. public class FlyingShip : MonoBehaviour
  33. {
  34.  
  35.     public float speed = 10f;
  36.     public float orbitingSpeed = 5f;
  37.     public float angle = 0;
  38.     private Vector3 position;
  39.  
  40.     void FixedUpdate()
  41.     {
  42.         // Rigidbody2D rigid = GetComponent<Rigidbody2D>();
  43.         // rigid.velocity.
  44.         // position = this.transform.position;
  45.         // position.y += 0.01f * speed;
  46.         // this.transform.position = position;
  47.         // transform.position = transform.position + VectorFromAngle(angle, speed);
  48.        
  49.     }
  50.  
  51.     void OnTriggerStay2D(Collider2D other) {
  52.        
  53.         Debug.Log(Input.GetKeyDown(KeyCode.A));
  54.         if (Input.GetKeyDown(KeyCode.A))
  55.         {
  56.             // PointEffector2D pte = other.gameObject.GetComponent<PointEffector2D>();
  57.             // Destroy(pte);
  58.             // GravityDetection.inTrigger = false;
  59.             // float distance = Vector2.Distance(transform.position, other.gameObject.transform.position);
  60.             // speed = distance * orbitingSpeed;
  61.             // angle = 90;
  62.         }
  63.     }
  64.  
  65.     void OnTriggerExit2D(Collider2D other)
  66.     {
  67.         GravityDetection.inTrigger = true;
  68.     }
  69.  
  70.     Vector3 VectorFromAngle(float theta, float speed) {
  71.         return new Vector3(Mathf.Cos(theta) * speed * Time.deltaTime, Mathf.Sin(theta) * speed * Time.deltaTime, 0);
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement