Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEditor;
- public class GravityDetection : MonoBehaviour
- {
- public float speed;
- public GameObject obj;
- public static bool inTrigger = false;
- private Vector3 zAxis = new Vector3(0, 0, 1);
- void FixedUpdate() {
- if (obj && inTrigger) {
- transform.RotateAround(obj.transform.position, zAxis, speed);
- }
- }
- void OnTriggerEnter2D(Collider2D other) {
- if (other.gameObject.CompareTag("Gravity Field")) {
- obj = other.gameObject;
- inTrigger = true;
- }
- }
- }
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class FlyingShip : MonoBehaviour
- {
- public float speed = 10f;
- public float orbitingSpeed = 5f;
- public float angle = 0;
- private Vector3 position;
- void FixedUpdate()
- {
- // Rigidbody2D rigid = GetComponent<Rigidbody2D>();
- // rigid.velocity.
- // position = this.transform.position;
- // position.y += 0.01f * speed;
- // this.transform.position = position;
- // transform.position = transform.position + VectorFromAngle(angle, speed);
- }
- void OnTriggerStay2D(Collider2D other) {
- Debug.Log(Input.GetKeyDown(KeyCode.A));
- if (Input.GetKeyDown(KeyCode.A))
- {
- // PointEffector2D pte = other.gameObject.GetComponent<PointEffector2D>();
- // Destroy(pte);
- // GravityDetection.inTrigger = false;
- // float distance = Vector2.Distance(transform.position, other.gameObject.transform.position);
- // speed = distance * orbitingSpeed;
- // angle = 90;
- }
- }
- void OnTriggerExit2D(Collider2D other)
- {
- GravityDetection.inTrigger = true;
- }
- Vector3 VectorFromAngle(float theta, float speed) {
- return new Vector3(Mathf.Cos(theta) * speed * Time.deltaTime, Mathf.Sin(theta) * speed * Time.deltaTime, 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement