2022-12-15 23:00:15 +08:00
|
|
|
|
using SHADE;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using static Item;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class PhysicsTestObj : Script
|
|
|
|
|
{
|
|
|
|
|
public RigidBody rb { 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 = 500.0f;
|
|
|
|
|
|
|
|
|
|
protected override void awake()
|
|
|
|
|
{
|
|
|
|
|
rb = GetComponent<RigidBody>();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 6; ++i)
|
|
|
|
|
{
|
|
|
|
|
move[i] = false;
|
|
|
|
|
rotate[i] = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void update()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 6; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (Input.GetKeyDown(moveInputKeys[i]))
|
|
|
|
|
move[i] = true;
|
|
|
|
|
|
2022-12-16 02:02:20 +08:00
|
|
|
|
if (Input.GetKeyDown(rotateInputKeys[i]))
|
|
|
|
|
rotate[i] = true;
|
2022-12-15 23:00:15 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void fixedUpdate()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 6; ++i)
|
|
|
|
|
{
|
|
|
|
|
bool shouldMove = move[i];
|
|
|
|
|
bool shouldRotate = rotate[i];
|
|
|
|
|
|
|
|
|
|
if (shouldMove)
|
|
|
|
|
{
|
2022-12-16 02:02:20 +08:00
|
|
|
|
//Vector3 offset = new Vector3(0.25f, 0.0f, 0.0f);
|
|
|
|
|
//rb.AddForceAtLocalPos(moveVec[i] * forceAmount, offset);
|
|
|
|
|
rb.AddForce(moveVec[i] * forceAmount);
|
2022-12-15 23:00:15 +08:00
|
|
|
|
move[i] = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (shouldRotate)
|
|
|
|
|
{
|
|
|
|
|
rb.AddTorque(rotateVec[i] * torqueAmount);
|
|
|
|
|
rotate[i] = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|