using SHADE; using System; using System.Collections.Generic; using static Item; public class PhysicsTestObj : Script { public Transform tf { get; set; } public RigidBody body { get; set; } public Collider collider { get; set; } // Movement input booleans public enum Direction { UP, DOWN, FORWARD, BACK, LEFT, RIGHT }; internal bool[] move = new bool[6]; internal bool[] rotate = new bool[6]; internal Vector3[] moveVec = new Vector3[6] { Vector3.Up, Vector3.Down, Vector3.Back, Vector3.Forward, Vector3.Left, Vector3.Right }; internal Vector3[] rotateVec = new Vector3[6] { Vector3.Right, Vector3.Left, Vector3.Forward, Vector3.Down, Vector3.Up, Vector3.Down }; internal Input.KeyCode[] moveInputKeys = new Input.KeyCode[6] { Input.KeyCode.Space, Input.KeyCode.LeftControl, Input.KeyCode.W, Input.KeyCode.S, Input.KeyCode.A, Input.KeyCode.D }; internal Input.KeyCode[] rotateInputKeys = new Input.KeyCode[6] { Input.KeyCode.I, Input.KeyCode.K, Input.KeyCode.U, Input.KeyCode.O, Input.KeyCode.J, Input.KeyCode.L }; public float forceAmount = 50.0f; public float torqueAmount = 25.0f; protected override void onTriggerEnter(CollisionInfo info) { Debug.Log("Trigger Enter"); } protected override void onTriggerStay(CollisionInfo info) { Debug.Log("Trigger Stay"); } protected override void onTriggerExit(CollisionInfo info) { Debug.Log("Trigger Exit"); } protected override void onCollisionEnter(CollisionInfo info) { Debug.Log("Collision Enter"); } protected override void onCollisionStay(CollisionInfo info) { Debug.Log("Collision Stay"); } protected override void onCollisionExit(CollisionInfo info) { Debug.Log("Collision Exit"); } protected override void awake() { tf = GetComponent(); body = GetComponent(); collider = GetComponent(); for (int i = 0; i < 6; ++i) { move[i] = false; rotate[i] = false; } } protected override void update() { GameObject? target = GameObject.Find("Target"); if (target.HasValue) { Physics.ColliderLineCast(collider.Owner, Vector3.Zero, target.Value.GetComponent().GlobalPosition, false, (ushort)64); } for (int i = 0; i < 6; ++i) { if (Input.GetKeyDown(moveInputKeys[i])) move[i] = true; if (Input.GetKeyDown(rotateInputKeys[i])) rotate[i] = true; } } protected override void fixedUpdate() { for (int i = 0; i < 6; ++i) { bool shouldMove = move[i]; bool shouldRotate = rotate[i]; if (shouldMove) { //Vector3 offset = new Vector3(0.25f, 0.0f, 0.0f); //rb.AddForceAtLocalPos(moveVec[i] * forceAmount, offset); body.AddForce(moveVec[i] * forceAmount); move[i] = false; } if (shouldRotate) { body.AddTorque(rotateVec[i] * torqueAmount); rotate[i] = false; } } } }