Merge branch 'SP3-2-Physics' into PlayerControllerWIthNewPhysics
This commit is contained in:
commit
59eb2d767f
|
@ -45,7 +45,7 @@
|
|||
Components:
|
||||
Transform Component:
|
||||
Translate: {x: 0.141888797, y: 5, z: 0}
|
||||
Rotate: {x: -0, y: 0, z: 0.490080774}
|
||||
Rotate: {x: -0, y: 0, z: 0}
|
||||
Scale: {x: 0.999999702, y: 0.999999702, z: 1}
|
||||
IsActive: true
|
||||
RigidBody Component:
|
||||
|
@ -68,9 +68,9 @@
|
|||
Collider Component:
|
||||
Colliders:
|
||||
- Is Trigger: false
|
||||
Collision Tag: 1
|
||||
Type: Sphere
|
||||
Radius: 1
|
||||
Collision Tag: 0
|
||||
Type: Box
|
||||
Half Extents: {x: 1, y: 1, z: 1}
|
||||
Friction: 0.400000006
|
||||
Bounciness: 0
|
||||
Density: 1
|
||||
|
@ -78,30 +78,8 @@
|
|||
Rotation Offset: {x: 0, y: 0, z: 0}
|
||||
IsActive: true
|
||||
Scripts:
|
||||
- Type: PhysicsTestObj
|
||||
- Type: MovementTest
|
||||
Enabled: true
|
||||
forceAmount: 50
|
||||
torqueAmount: 25
|
||||
- EID: 2
|
||||
Name: Default
|
||||
IsActive: true
|
||||
NumberOfChildren: 0
|
||||
Components:
|
||||
Transform Component:
|
||||
Translate: {x: 0.34412086, y: 3.23541069, z: 0}
|
||||
Rotate: {x: 0, y: 0, z: 0.490080804}
|
||||
Scale: {x: 0.999999702, y: 0.999999702, z: 1}
|
||||
IsActive: true
|
||||
Collider Component:
|
||||
Colliders:
|
||||
- Is Trigger: false
|
||||
Collision Tag: 0
|
||||
Type: Sphere
|
||||
Radius: 1
|
||||
Friction: 0.400000006
|
||||
Bounciness: 0
|
||||
Density: 1
|
||||
Position Offset: {x: 0, y: 0, z: 0}
|
||||
Rotation Offset: {x: 0, y: 0, z: 0}
|
||||
IsActive: false
|
||||
Scripts: ~
|
||||
forceAmount: 25
|
||||
torqueAmount: 50
|
||||
rayDistance: 1
|
|
@ -0,0 +1,80 @@
|
|||
using SHADE;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static Item;
|
||||
|
||||
|
||||
public class MovementTest : Script
|
||||
{
|
||||
public Transform tf { get; set; }
|
||||
public RigidBody body { get; set; }
|
||||
|
||||
// Movement input booleans
|
||||
internal bool move = false;
|
||||
internal bool[] rotate = new bool[2];
|
||||
|
||||
internal Vector3[] rotateVec = new Vector3[2]
|
||||
{
|
||||
Vector3.Up,
|
||||
Vector3.Down
|
||||
};
|
||||
|
||||
internal Input.KeyCode[] rotateInputKeys = new Input.KeyCode[2]
|
||||
{
|
||||
Input.KeyCode.J,
|
||||
Input.KeyCode.L
|
||||
};
|
||||
|
||||
public float forceAmount = 50.0f;
|
||||
public float torqueAmount = 100.0f;
|
||||
public float rayDistance = 1.0f;
|
||||
|
||||
protected override void awake()
|
||||
{
|
||||
tf = GetComponent<Transform>();
|
||||
body = GetComponent<RigidBody>();
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
rotate[i] = false;
|
||||
}
|
||||
|
||||
protected override void update()
|
||||
{
|
||||
if (Input.GetKey(Input.KeyCode.W))
|
||||
move = true;
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
if (Input.GetKeyDown(rotateInputKeys[i]))
|
||||
rotate[i] = true;
|
||||
}
|
||||
|
||||
Vector3 dirNor = tf.Forward;
|
||||
List<RaycastHit> rayList1 = Physics.ColliderRaycast(GameObject, new Ray(Vector3.Zero, Vector3.RotateY(dirNor, SHADE.Math.DegreesToRadians(22.5f))), rayDistance, false, (ushort)65535);
|
||||
List<RaycastHit> rayList2 = Physics.ColliderRaycast(GameObject, new Ray(Vector3.Zero, Vector3.RotateY(dirNor, SHADE.Math.DegreesToRadians(-22.5f))), rayDistance, false, (ushort)65535);
|
||||
List<RaycastHit> rayList3 = Physics.ColliderRaycast(GameObject, new Ray(Vector3.Zero, dirNor), rayDistance, false, (ushort)65535);
|
||||
}
|
||||
|
||||
protected override void fixedUpdate()
|
||||
{
|
||||
if (move)
|
||||
{
|
||||
// Apply force in the direction the box is facing
|
||||
// AKA Transform's forward
|
||||
body.AddForce(tf.Forward * forceAmount);
|
||||
Debug.Log($"Forward: <{tf.Forward.x}, {tf.Forward.y}, {tf.Forward.z}");
|
||||
move = false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
bool shouldRotate = rotate[i];
|
||||
|
||||
if (shouldRotate)
|
||||
{
|
||||
body.AddTorque(rotateVec[i] * torqueAmount);
|
||||
rotate[i] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
Name: MovementTest
|
||||
ID: 164554656
|
||||
Type: 9
|
|
@ -45,7 +45,7 @@ namespace SHADE
|
|||
///<summary>
|
||||
/// Shorthand for writing Vector3(0, 0, -1).
|
||||
///</summary>
|
||||
static initonly Vector3 Back = Vector3(0.0f, 0.0f, -1.0f);
|
||||
static initonly Vector3 Back = Vector3(0.0f, 0.0f, 1.0f);
|
||||
///<summary>
|
||||
/// Shorthand for writing Vector3(0, -1, 0).
|
||||
///</summary>
|
||||
|
@ -53,7 +53,7 @@ namespace SHADE
|
|||
///<summary>
|
||||
/// Shorthand for writing Vector3(0, 0, 1).
|
||||
///</summary>
|
||||
static initonly Vector3 Forward = Vector3(0.0f, 0.0f, 1.0f);
|
||||
static initonly Vector3 Forward = Vector3(0.0f, 0.0f, -1.0f);
|
||||
///<summary>
|
||||
/// Shorthand for writing Vector3(-1, 0, 0).
|
||||
///</summary>
|
||||
|
|
Loading…
Reference in New Issue