diff --git a/.vsconfig b/.vsconfig new file mode 100644 index 0000000..d70cd98 --- /dev/null +++ b/.vsconfig @@ -0,0 +1,6 @@ +{ + "version": "1.0", + "components": [ + "Microsoft.VisualStudio.Workload.ManagedGame" + ] +} diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 1ab48db..7b20bd5 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -3760,6 +3760,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 10fb806d393482e43b540cd3b9d1f5ac, type: 3} m_Name: m_EditorClassIdentifier: + debug: 0 _onInteract: m_PersistentCalls: m_Calls: @@ -3816,9 +3817,9 @@ MonoBehaviour: m_EditorClassIdentifier: moveSpeed: 20 lookatOffset: {x: 0, y: 0, z: -90} - rb: {fileID: 0} turnSpeed: 3 dismountAnchor: {fileID: 1031673585} + currentStation: {fileID: 0} --- !u!60 &143589115 PolygonCollider2D: m_ObjectHideFlags: 0 @@ -3916,9 +3917,11 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d4b25a13b3b589a44aa2945dbb9af0d3, type: 3} m_Name: m_EditorClassIdentifier: - rb: {fileID: 0} grounded: 1 groundedDrag: 2 + flightDrag: 0 + groundedAngularDrag: 1 + flightAngularDrag: 0 --- !u!1 &145654670 GameObject: m_ObjectHideFlags: 0 @@ -4497,9 +4500,11 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d4b25a13b3b589a44aa2945dbb9af0d3, type: 3} m_Name: m_EditorClassIdentifier: - rb: {fileID: 0} grounded: 1 groundedDrag: 10 + flightDrag: 0 + groundedAngularDrag: 1 + flightAngularDrag: 0 --- !u!1 &159061383 GameObject: m_ObjectHideFlags: 0 @@ -8273,6 +8278,7 @@ MonoBehaviour: m_EditorClassIdentifier: inverseSquare: 1 g: 1 + debug: 0 --- !u!58 &383183500 CircleCollider2D: m_ObjectHideFlags: 0 @@ -16506,9 +16512,11 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d4b25a13b3b589a44aa2945dbb9af0d3, type: 3} m_Name: m_EditorClassIdentifier: - rb: {fileID: 0} grounded: 0 groundedDrag: 1 + flightDrag: 0 + groundedAngularDrag: 1 + flightAngularDrag: 0 --- !u!114 &826203411 MonoBehaviour: m_ObjectHideFlags: 0 @@ -16521,8 +16529,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 3e324d1c67a616a4e96c285c02205388, type: 3} m_Name: m_EditorClassIdentifier: - rb: {fileID: 0} initialImpulse: {x: 0, y: 800, z: 0} + debug: 0 --- !u!50 &826203412 Rigidbody2D: serializedVersion: 4 @@ -24149,6 +24157,7 @@ MonoBehaviour: m_EditorClassIdentifier: inverseSquare: 1 g: 2.5 + debug: 0 --- !u!58 &1043146800 CircleCollider2D: m_ObjectHideFlags: 0 @@ -30478,6 +30487,7 @@ MonoBehaviour: m_EditorClassIdentifier: inverseSquare: 1 g: 0.5 + debug: 0 --- !u!58 &1340137743 CircleCollider2D: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Entity/Entity.cs b/Assets/Scripts/Entity/Entity.cs index 0635a70..09e45fc 100644 --- a/Assets/Scripts/Entity/Entity.cs +++ b/Assets/Scripts/Entity/Entity.cs @@ -12,12 +12,22 @@ public class Entity : MonoBehaviour [SerializeField] private float groundedDrag = 1; + [SerializeField] + private float flightDrag = 0; + + [SerializeField] + private float groundedAngularDrag = 1f; + [SerializeField] + private float flightAngularDrag = 0.00f; private PlayerController playerController; public Rigidbody2D RigidBody { get => rigidBody; private set => rigidBody = value; } public bool Grounded { get => grounded; set => grounded = value; } public float GroundedDrag { get => groundedDrag; set => groundedDrag = value; } + public float FlightDrag { get => flightDrag; set => flightDrag = value; } + public float FlightAngularDrag { get => flightAngularDrag; set => flightAngularDrag = value; } + public float GroundedAngularDrag { get => groundedAngularDrag; set => groundedAngularDrag = value; } public PlayerController PlayerController { get => playerController; set => playerController = value; } //[SerializeField] @@ -38,7 +48,9 @@ private void OnTriggerEnter2D(Collider2D other) { if(other.tag == "Gravity") { Grounded = true; //rb.velocity = Vector3.zero; + RigidBody.drag = GroundedDrag; + RigidBody.angularDrag = GroundedAngularDrag; } } @@ -46,7 +58,8 @@ private void OnTriggerExit2D(Collider2D other) { if(other.tag == "Gravity") { Grounded = false; //rb.AddForce(); - RigidBody.drag = 0; + RigidBody.drag = FlightDrag; + RigidBody.angularDrag = FlightAngularDrag; if(PlayerController != null && RigidBody.velocity.magnitude <= 5) { //Vector3 force = new Vector3(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")) * (PlayerController.moveSpeed * (PlayerController.walkSpeedMod * 10f)); diff --git a/Assets/Scripts/Entity/GravityWell.cs b/Assets/Scripts/Entity/GravityWell.cs index a40f142..cd92562 100644 --- a/Assets/Scripts/Entity/GravityWell.cs +++ b/Assets/Scripts/Entity/GravityWell.cs @@ -8,9 +8,9 @@ public class GravityWell : MonoBehaviour //private Collider2D gravityInfluence; [SerializeField] private bool inverseSquare = true; - public float g = 0.5f; - + [SerializeField] + private bool debug = false; private List entities = new List(); private void FixedUpdate() { @@ -44,7 +44,7 @@ private void OnTriggerEnter2D(Collider2D other) { } } - Debug.Log("Entered influence of " + gameObject.name); + if(debug) Debug.Log("Entered influence of " + gameObject.name); } private void OnTriggerExit2D(Collider2D other) { @@ -56,6 +56,6 @@ private void OnTriggerExit2D(Collider2D other) { entity = entities.Find(element => element.gameObject == other.gameObject); entities.Remove(entity); - Debug.Log("Left influence of " + gameObject.name); + if(debug) Debug.Log("Left influence of " + gameObject.name); } } diff --git a/Assets/Scripts/Interactable/Interactable.cs b/Assets/Scripts/Interactable/Interactable.cs index 0075061..2d07d05 100644 --- a/Assets/Scripts/Interactable/Interactable.cs +++ b/Assets/Scripts/Interactable/Interactable.cs @@ -4,6 +4,9 @@ using UnityEngine.Events; public class Interactable : MonoBehaviour { + [SerializeField] + private bool debug = false; + [SerializeField] private UnityEvent _onInteract; public UnityEvent OnInteract @@ -33,22 +36,22 @@ public UnityEvent OnHoverExit } public void Interact() { - Debug.Log(gameObject.name + " Interact"); + if(debug) Debug.Log(gameObject.name + " Interact"); OnInteract?.Invoke(); } public void InvokeOnEnter() { - Debug.Log(gameObject.name + " OnEnter"); + if(debug) Debug.Log(gameObject.name + " OnEnter"); OnHoverEnter?.Invoke(); } public void InvokeOnExit() { - Debug.Log(gameObject.name + " OnExit"); + if(debug) Debug.Log(gameObject.name + " OnExit"); OnHoverExit?.Invoke(); } public void InvokeOnHover() { - //Debug.Log(gameObject.name + " OnHover"); + //if(debug) Debug.Log(gameObject.name + " OnHover"); OnHover?.Invoke(); } } diff --git a/Assets/Scripts/Player/PlayerController.cs b/Assets/Scripts/Player/PlayerController.cs index da587dc..489970f 100644 --- a/Assets/Scripts/Player/PlayerController.cs +++ b/Assets/Scripts/Player/PlayerController.cs @@ -76,6 +76,7 @@ public void EnterVehicle(Vehicle vehicle) { if(currentVehicle == null) { currentVehicle = vehicle; + // TODO seat anchor position on the vehicle transform.position = vehicle.transform.position; transform.parent = vehicle.transform; RigidBody.simulated = false; @@ -91,8 +92,8 @@ public void ExitVehicle() transform.position = currentVehicle.dismountAnchor.position; transform.parent = null; RigidBody.simulated = true; - if(currentStation) { - RigidBody.velocity = currentVehicle.RigidBody.velocity + currentStation.RigidBody.velocity; + if(currentVehicle.currentStation) { + RigidBody.velocity = currentVehicle.currentStation.RigidBody.velocity; } else { RigidBody.velocity = currentVehicle.RigidBody.velocity; } @@ -109,7 +110,10 @@ public void ExitVehicle() private void OnTriggerEnter2D(Collider2D other) { if(other.tag == "Gravity") { grounded = true; - currentStation = other.gameObject.GetComponent(); + + if(!other.gameObject.TryGetComponent(out currentStation)) { + currentStation = other.gameObject.GetComponentInParent(); + } // if(other.gameObject.TryGetComponent(out currentStation)) { @@ -127,7 +131,10 @@ private void OnTriggerExit2D(Collider2D other) { // rb.AddForce(rb.velocity); // } - if(currentStation != null && currentStation.gameObject == other.gameObject) { + // TODO Really need to figure this out + // If a station is within another station + // There was another issue i saw but i cant think of it right now + if(currentStation != null) { //&& currentStation.gameObject == other.gameObject) { currentStation = null; } } diff --git a/Assets/Scripts/Structure/Station.cs b/Assets/Scripts/Structure/Station.cs index 9cd6f8c..60dea67 100644 --- a/Assets/Scripts/Structure/Station.cs +++ b/Assets/Scripts/Structure/Station.cs @@ -9,11 +9,15 @@ public class Station : MonoBehaviour private List entities; private Vector3 lastPosition; + private Vector3 _localVelocity; [SerializeField] private Vector3 initialImpulse; + [SerializeField] + private bool debug = false; public Rigidbody2D RigidBody { get => _rigidBody; protected set => _rigidBody = value; } + public Vector3 LocalVelocity { get => _localVelocity; set => _localVelocity = value; } // Start is called before the first frame update void Start() @@ -29,15 +33,16 @@ void Start() } RigidBody.AddForce(initialImpulse); + LocalVelocity = transform.position - lastPosition; } // Update is called once per frame void Update() { - Vector3 velocity = transform.position - lastPosition; + LocalVelocity = transform.position - lastPosition; foreach(Entity entity in entities) { - entity.transform.Translate(velocity, transform); - //entity.transform.position += velocity; + entity.transform.Translate(LocalVelocity, transform); + //entity.transform.position += LocalVelocity; } lastPosition = transform.position; @@ -51,7 +56,7 @@ private void OnTriggerEnter2D(Collider2D other) { entity.RigidBody.velocity = entity.RigidBody.velocity - RigidBody.velocity; } - Debug.Log("Entered influence of " + gameObject.name); + if(debug) Debug.Log("Entered influence of " + gameObject.name); } private void OnTriggerExit2D(Collider2D other) { @@ -61,6 +66,6 @@ private void OnTriggerExit2D(Collider2D other) { entity.RigidBody.velocity = entity.RigidBody.velocity + RigidBody.velocity; } - Debug.Log("Left influence of " + gameObject.name); + if(debug) Debug.Log("Left influence of " + gameObject.name); } } diff --git a/Assets/Scripts/Vehicle/Vehicle.cs b/Assets/Scripts/Vehicle/Vehicle.cs index a250bcc..b4c8cad 100644 --- a/Assets/Scripts/Vehicle/Vehicle.cs +++ b/Assets/Scripts/Vehicle/Vehicle.cs @@ -11,6 +11,9 @@ public class Vehicle : Controllable public Transform dismountAnchor; + [HideInInspector] + public Station currentStation; + // Start is called before the first frame update protected override void Start() { base.Start(); @@ -83,4 +86,20 @@ protected override void LookAt(Vector3 position) //rb.MoveRotation(targetRotation); //rb.MoveRotation(Quaternion.Lerp(Quaternion.Euler(0,0,rb.rotation), targetRotation, Time.fixedDeltaTime * turnSpeed)); } + + private void OnTriggerEnter2D(Collider2D other) { + if(other.tag == "Gravity") { + if(!other.gameObject.TryGetComponent(out currentStation)) { + currentStation = other.gameObject.GetComponentInParent(); + } + } + } + + private void OnTriggerExit2D(Collider2D other) { + if(other.tag == "Gravity") { + if(currentStation != null) { + currentStation = null; + } + } + } }