Updated Player and MainGame scene, fix bugs #281

Merged
glencelow merged 7 commits from PlayerController into main 2022-11-25 16:34:51 +08:00
5 changed files with 62 additions and 136 deletions
Showing only changes of commit c07fa3c5ae - Show all commits

View File

@ -8236,15 +8236,7 @@
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 0.200000003, y: 0.200000003, z: 0.200000003}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
- Is Trigger: true
Type: Box
Half Extents: {x: 0.400000006, y: 0.400000006, z: 0.400000006}
Half Extents: {x: 0.100000001, y: 0.100000001, z: 0.100000001}
Friction: 0.400000006
Bounciness: 0
Density: 1
@ -8288,15 +8280,7 @@
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 0.5, y: 0.150000006, z: 0.5}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
- Is Trigger: true
Type: Box
Half Extents: {x: 0.699999988, y: 0.300000012, z: 0.75}
Half Extents: {x: 0.25, y: 0.075000003, z: 0.25}
Friction: 0.400000006
Bounciness: 0
Density: 1
@ -8340,15 +8324,7 @@
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 0.300000012, y: 0.300000012, z: 0.300000012}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
- Is Trigger: true
Type: Box
Half Extents: {x: 0.5, y: 0.5, z: 0.5}
Half Extents: {x: 0.150000006, y: 0.150000006, z: 0.150000006}
Friction: 0.400000006
Bounciness: 0
Density: 1
@ -8558,10 +8534,12 @@
heavyMultiper: 0.25
- Type: PickAndThrow
Enabled: true
throwForce: [50, 50, 50]
throwForce: [8, 10, 8]
item: 51000
delayTimer: 1
aimingLength: 0.5
rayDistance: 1
inRange: false
rayDistance: 0.5
- EID: 3
Name: HoldingPoint
IsActive: true
@ -8634,62 +8612,3 @@
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Scripts: ~
- EID: 196
Name: ====AI=====
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 2.70000005, y: 0.100000001, z: -2}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 140697366
Material: 129495479
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: false
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: true
Freeze Rotation Y: false
Freeze Rotation Z: true
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 1, y: 1.79999995, z: 0.400000006}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0.899999976, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts:
- Type: Homeowner1
Enabled: true
player: 2
waypoints:
- [2.70000005, 0, -2]
- [-0.300000012, 0, -2.70000005]
- [-2, 0, -3.79999995]
- [-4, 0, -2.0999999]
- [-2.9000001, 0, 2.4000001]
- [-1, 0, 4]
- [2.70000005, 0, 4]
patrolSpeed: 1
chaseSpeed: 2
turningSpeed: 5
sightDistance: 8
eyeOffset: [0, 0, 0]
distanceToCapture: 0.5
captureTime: 0.5
footstepSFXIntervalMultiplier: 0.5

View File

@ -7,7 +7,7 @@ using static Item;
public class PickAndThrow : Script
{
public Vector3 throwForce = new Vector3(100.0f, 200.0f, 100.0f);
public GameObject item { get; set; }
public GameObject item;
public float delayTimer = 1.0f;
public float aimingLength = 1.5f;
@ -17,18 +17,16 @@ public class PickAndThrow : Script
private Transform itemTransform;
private RigidBody itemRidibody;
private Transform raccoonHoldLocation;
private Transform playerTran;
private Item itemScript;
private ThirdPersonCamera tpc;
private float lastXDir;
private float lastZDir;
private bool inRange = false;
public bool inRange = false;
private Collider collider;
private BoxCollider cs;
[Tooltip("Lenght of ray")]
public float rayDistance = 3;
public float rayDistance = 1;
protected override void awake()
{
@ -49,7 +47,6 @@ public class PickAndThrow : Script
Debug.LogError("COLLIDER EMPTY");
else
{
cs = collider.GetCollisionShape<BoxCollider>(0);
}
timer = delayTimer;
@ -60,13 +57,14 @@ public class PickAndThrow : Script
timer += Time.DeltaTimeF;
CalculateDir();
CastRay();
if (pc && itemRidibody && itemTransform)
{
if (pc.holdItem)
{
itemTransform.LocalPosition = raccoonHoldLocation.GlobalPosition;
itemTransform.LocalRotation = playerTran.LocalRotation;
itemTransform.LocalRotation = pc.tranform.LocalRotation;
if (Input.GetMouseButtonDown(Input.MouseCode.LeftButton))
{
@ -86,6 +84,7 @@ public class PickAndThrow : Script
if (itemScript)
{
Vector3 vec = new Vector3(throwForce.x * lastXDir, throwForce.y, throwForce.z * lastZDir);
//to be change
if (itemScript.currCategory == ItemCategory.LIGHT)
itemRidibody.AddForce(vec * 0.3f);
if (itemScript.currCategory == ItemCategory.MEDIUM)
@ -130,7 +129,6 @@ public class PickAndThrow : Script
protected override void fixedUpdate()
{
CastRay();
}
private void ResetItemObject()
@ -144,7 +142,7 @@ public class PickAndThrow : Script
private void RetrieveItemComponets()
{
//get the transform of the given item
if (item.GetScript<Item>() && itemTransform == null && itemRidibody == null)
if (item.GetScript<Item>() && !itemTransform && !itemRidibody )
{
itemRidibody = item.GetComponent<RigidBody>();
if (itemRidibody == null)
@ -187,43 +185,34 @@ public class PickAndThrow : Script
private void CastRay()
{
if (pc != null && cs != null)
if (pc != null)
{
Vector3 dirNor = pc.tranform.Forward;
//change when cs.HalfExtents.z works
//cs.HalfExtents.z
Vector3 playerRayPos = pc.tranform.GlobalPosition + (dirNor * (0.3f + 0.1f));
playerRayPos.y += 0.1f;
Vector3 playerRayPos = pc.tranform.GlobalPosition;
playerRayPos.y += 0.05f;
dirNor.Normalise();
RaycastHit ray1 = Physics.Raycast(new Ray(playerRayPos, Vector3.RotateY(dirNor, SHADE.Math.DegreesToRadians(22.5f))), rayDistance);
RaycastHit ray2 = Physics.Raycast(new Ray(playerRayPos, Vector3.RotateY(dirNor, SHADE.Math.DegreesToRadians(-22.5f))), rayDistance);
RaycastHit ray3 = Physics.Raycast(new Ray(playerRayPos, dirNor), rayDistance * 0.5f);
RaycastHit ray3 = Physics.Raycast(new Ray(playerRayPos, dirNor), rayDistance * 0.75f);
inRange = CheckForItem(ray1) || CheckForItem(ray2) || CheckForItem(ray3);
}
}
protected override void onCollisionEnter(CollisionInfo info)
private bool CheckForItem(RaycastHit ray)
{
}
protected override void onTriggerEnter(CollisionInfo info)
if (ray.Hit)
{
if (info.GameObject.GetScript<Item>() && !pc.holdItem)
if (ray.Other.Value.GetScript<Item>() && !pc.holdItem)
{
item = info.GameObject;
inRange = true;
}
}
protected override void onTriggerStay(CollisionInfo info)
{
//Debug.Log("STAY");
}
protected override void onTriggerExit(CollisionInfo info)
{
//Debug.Log("EXIT");
if (info.GameObject.GetScript<Item>() != null && !pc.holdItem)
{
inRange = false;
item = ray.Other.Value;
return true;
}
else
return false;
}
return false;
}
}

View File

@ -42,17 +42,12 @@ public class GameManager : Script
Score = 0;
currGameState = GameState.START;
if (zonePool)
{
listOfZone = zonePool.GetScriptsInChildren<ScoringZone>();
if (listOfZone != null)
foreach (ScoringZone sz in listOfZone)
sz.gameManger = Owner.GetScript<GameManager>();
}
}
protected override void update()
{
Cheats();
if (once)
{
if (itemPool)
@ -62,6 +57,14 @@ public class GameManager : Script
foreach (Item i in listOfItems)
totalItemCount += 1;
}
if (zonePool)
{
listOfZone = zonePool.GetScriptsInChildren<ScoringZone>();
if (listOfZone != null)
foreach (ScoringZone sz in listOfZone)
sz.gameManger = Owner.GetScript<GameManager>();
}
once = false;
}
@ -86,4 +89,20 @@ public class GameManager : Script
}
}
private void Cheats()
{
if (Input.GetKeyDown(Input.KeyCode.F1))
{
SceneManager.ChangeScene(loseScene);
}
if (Input.GetKeyDown(Input.KeyCode.F2))
{
SceneManager.ChangeScene(winScene);
}
if (Input.GetKeyDown(Input.KeyCode.Escape))
{
SceneManager.ChangeScene(97158628);
}
}
}

View File

@ -9,14 +9,14 @@ public class MainMenu : Script
}
protected override void update()
{
if (Input.GetKey(Input.KeyCode.Space))
if (Input.GetKeyDown(Input.KeyCode.Space))
{
Audio.PlaySFXOnce2D("event:/UI/mouse_down_element");
SceneManager.ChangeScene(86098106);
Audio.StopAllSounds();
}
if (Input.GetKey(Input.KeyCode.Escape))
if (Input.GetKeyDown(Input.KeyCode.Escape))
{
Audio.StopAllSounds();
Application.Quit();

View File

@ -144,7 +144,6 @@ namespace SHADE
// HACK: Clamp DT here to prevent a ridiculous amount of updates. This limits updates from large dt to 2.
// HACK: This should be done by the FRC and not here for predictable behaviour.
dt = std::clamp(dt, 0.0, 1.0 / 30.0);
accumulatedTime += dt;
//testFunction();