Bug fixes and new assets #246

Merged
glencelow merged 10 commits from PlayerController into main 2022-11-22 16:25:14 +08:00
6 changed files with 140 additions and 102 deletions
Showing only changes of commit 293cc586d1 - Show all commits

View File

@ -69,8 +69,8 @@
NumberOfChildren: 3
Components:
Transform Component:
Translate: {x: -21.4454765, y: -3.67383885, z: -3.43293667}
Rotate: {x: -0, y: 0, z: 0}
Translate: {x: 0.214953125, y: -3.67369676, z: -3.03063416}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 2, y: 2, z: 2}
IsActive: true
Renderable Component:
@ -83,7 +83,7 @@
Drag: 2
Angular Drag: 0
Use Gravity: false
Interpolate: false
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: false
@ -108,7 +108,7 @@
maxMoveVel: 4
moveForce: 50
sprintMultiplier: 1.5
rotationFactorPerFrame: 1
rotationFactorPerFrame: 4
maxJumpHeight: 4
maxJumpTime: 0.75
fallMultipler: 2
@ -116,7 +116,9 @@
mediumMultiper: 0.5
heavyMultiper: 0.25
- Type: PickAndThrow
throwForce: [200, 300, 200]
throwForce: [300, 300, 300]
delayTimer: 1
aimingLength: 1.5
- EID: 3
Name: HoldingPoint
IsActive: true
@ -135,13 +137,13 @@
Components:
Transform Component:
Translate: {x: 0, y: 0, z: 0}
Rotate: {x: -0.607372105, y: 4.78226185, z: 0}
Rotate: {x: -0.361278683, y: 4.97423792, z: 0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Camera Component:
Position: {x: -21.4454765, y: -3.67383885, z: -3.43293667}
Pitch: -34.7998581
Yaw: 274.003418
Position: {x: 0.214953125, y: -3.67369676, z: -3.03063416}
Pitch: -20.6997433
Yaw: 285.002838
Roll: 0
Width: 1920
Height: 1080
@ -287,8 +289,8 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 3.19867921, y: -3.66373587, z: -4.99996376}
Rotate: {x: -9.79829474e-06, y: 1.93362598e-06, z: 2.07606699e-05}
Translate: {x: 3.19865847, y: -3.66369891, z: -4.99997044}
Rotate: {x: -1.62010674e-05, y: 2.19047888e-06, z: 6.4769687e-05}
Scale: {x: 2, y: 2, z: 2}
IsActive: true
Renderable Component:
@ -298,10 +300,10 @@
RigidBody Component:
Type: Dynamic
Mass: 1
Drag: 0
Angular Drag: 0
Drag: 0.100000001
Angular Drag: 0.100000001
Use Gravity: true
Interpolate: false
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: false
@ -337,9 +339,9 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -21.4424801, y: -1.21456838, z: -1.82083583}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 2, y: 2, z: 2}
Translate: {x: -5.02078199, y: -1.27369666, z: -2.14885736}
Rotate: {x: -9.82871934e-05, y: 0.000654734089, z: -3.21757163e-08}
Scale: {x: 1.99998975, y: 2, z: 1.99998975}
IsActive: true
Renderable Component:
Mesh: 144838771
@ -348,10 +350,10 @@
RigidBody Component:
Type: Dynamic
Mass: 1
Drag: 5
Angular Drag: 1
Drag: 0.100000001
Angular Drag: 0.100000001
Use Gravity: true
Interpolate: false
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: false

View File

@ -1,4 +1,5 @@
using SHADE;
using SHADE_Scripting;
using System;
using static PlayerController;
@ -6,24 +7,47 @@ public class PickAndThrow : Script
{
public Vector3 throwForce = new Vector3(100.0f, 200.0f, 100.0f);
public GameObject item { get; set; }
public float delayTimer = 1.0f;
public float aimingLength = 1.5f;
private float timer;
private PlayerController pc;
private Camera cam;
private Transform itemTransform;
private RigidBody itemRidibody;
private Transform raccoonHoldLocation;
private Transform playerTran;
private ThirdPersonCamera tpc;
private float lastXDir;
private float lastZDir;
private bool inRange = false;
protected override void awake()
{
playerTran = GetComponent<Transform>();
if (playerTran)
Debug.Log("PLAYERTRANSFORM EMPTY"); ;
pc = GetScript<PlayerController>();
if(!pc)
Debug.Log("PLAYER CONTROLLER EMPTY");
raccoonHoldLocation = GetComponentInChildren<Transform>();
if (raccoonHoldLocation == null)
Debug.Log("CHILD EMPTY");
tpc = GetScriptInChildren<ThirdPersonCamera>();
if(!tpc)
Debug.Log("TPC EMPTY");
timer = delayTimer;
}
protected override void update()
{
if(timer <= delayTimer)
timer += Time.DeltaTimeF;
CalculateDir();
if (pc && itemRidibody && itemTransform)
@ -31,15 +55,27 @@ public class PickAndThrow : Script
if (pc.holdItem)
{
itemTransform.LocalPosition = raccoonHoldLocation.GlobalPosition;
itemTransform.LocalRotation = playerTran.LocalRotation;
if (Input.GetMouseButtonDown(Input.MouseCode.LeftButton))
{
Debug.Log("AIMING");
pc.isAiming = true;
pc.camArm.ArmLength = aimingLength;
}
if (Input.GetMouseButtonUp(Input.MouseCode.LeftButton) && pc.isAiming)
{
pc.isAiming = false;
if(tpc)
pc.camArm.ArmLength = tpc.armLength;
pc.holdItem = false;
inRange = false;
itemRidibody.IsGravityEnabled = true;
itemRidibody.AddForce(new Vector3(throwForce.x * lastXDir, throwForce.y, throwForce.z * lastZDir));
itemRidibody.LinearVelocity += pc.rb.LinearVelocity;
ResetItemObject();
timer = 0.0f;
}
if (Input.GetMouseButtonDown(Input.MouseCode.RightButton))
@ -54,12 +90,16 @@ public class PickAndThrow : Script
itemRidibody.IsGravityEnabled = true;
}
if (pc && !pc.holdItem && inRange && Input.GetMouseButtonDown(Input.MouseCode.LeftButton))
if (timer > delayTimer && pc && !pc.holdItem && inRange && Input.GetMouseButtonDown(Input.MouseCode.LeftButton))
{
if (pc.currentState == RaccoonStates.WALKING || pc.currentState == RaccoonStates.IDLE)
{
Debug.Log("PCIKUP");
pc.holdItem = true;
RetrieveItemComponets();
}
}
}
private void ResetItemObject()
{
@ -108,12 +148,17 @@ public class PickAndThrow : Script
}
}
private void DelayCheck()
{
timer += Time.DeltaTimeF;
}
protected override void onCollisionEnter(CollisionInfo info)
{
}
protected override void onTriggerEnter(CollisionInfo info)
{
if (info.GameObject.GetScript<Item>() != null && !pc.holdItem)
if (info.GameObject.GetScript<Item>() && !pc.holdItem)
{
item = info.GameObject;
inRange = true;

View File

@ -29,10 +29,12 @@ public class PlayerController : Script
public RigidBody rb { get; set; }
private Transform tranform;
private Camera cam;
public CameraArm camArm { get; set; }
private PickAndThrow pat;
private StateMachine stateMachine;
public bool holdItem { get; set; }
public bool isAiming { get; set; }
[Tooltip("The current state fo the raccoon")]
public RaccoonStates currentState = RaccoonStates.IDLE;
@ -49,24 +51,18 @@ public class PlayerController : Script
private float maxOldVel;
private bool sprintIncreaseOnce = false;
public float xAxisMove { get; set; }
public float zAxisMove { get; set; }
public Vector2 axisMove { get; set; }
public bool isMoveKeyPress { get; set; }
[Tooltip("curr not working")]
[Tooltip("How fast player will turn")]
public float rotationFactorPerFrame = 1.0f;
//Jumping vars==================================================================
[SerializeField]
[Tooltip("max height of the jump")]
public float maxJumpHeight = 4.0f;
[SerializeField]
[Tooltip("max amt of time it will take for the jump")]
public float maxJumpTime = 0.75f;
[SerializeField]
[Tooltip("increase gravity when falling")]
public float fallMultipler = 2.0f;
private float initialJumpVel;
@ -75,8 +71,11 @@ public class PlayerController : Script
private float groundGravity = -0.5f;
//ItemMultipler==================================================================
[Tooltip("How light item will affect player jump")]
public float lightMultiper = 0.75f;
[Tooltip("How medium item will affect player jump")]
public float mediumMultiper = 0.5f;
[Tooltip("How heavy item will affect player jump")]
public float heavyMultiper = 0.25f;
protected override void awake()
@ -84,6 +83,7 @@ public class PlayerController : Script
//default setup
isMoveKeyPress = false;
holdItem = false;
isAiming = false;
//Jump setup
float timeToApex = maxJumpTime / 2;
@ -94,11 +94,6 @@ public class PlayerController : Script
rb = GetComponent<RigidBody>();
if (rb == null)
Debug.LogError("RigidBody is NULL!");
else
{
rb.IsGravityEnabled = false;
rb.Interpolating = false;
}
//Transform check
tranform = GetComponent<Transform>();
@ -125,9 +120,12 @@ public class PlayerController : Script
protected override void update()
{
if (cam == null)
if (!cam)
cam = GetComponentInChildren<Camera>();
if(!camArm)
camArm = GetComponentInChildren<CameraArm>();
Rotation();
GotCaught();
//Debug.Log($"{currentState}");
//Debug.Log($" axisX: {axisMove.x} axisY:{axisMove.y}");
@ -137,9 +135,6 @@ public class PlayerController : Script
protected override void fixedUpdate()
{
//Rotation();
MoveKey();
Move();
Sprint();
@ -210,9 +205,7 @@ public class PlayerController : Script
{
rb.LinearVelocity += new Vector3(axisMove.x * moveForce, 0.0f, axisMove.y * moveForce) * Time.DeltaTimeF;
if (isMoveKeyPress)
{
if (rb)
if (isMoveKeyPress && rb)
{
Vector3 velNor = rb.LinearVelocity;
velNor.y = 0.0f;
@ -223,8 +216,6 @@ public class PlayerController : Script
rb.LinearVelocity = new Vector3(velNor.x, rb.LinearVelocity.y, velNor.z);
}
}
}
}
}
@ -293,19 +284,17 @@ public class PlayerController : Script
private void Rotation()
{
Vector3 poitionToLookAt;
poitionToLookAt.x = axisMove.x;
poitionToLookAt.y = 0.0f;
poitionToLookAt.z = axisMove.y;
if (tranform != null)
if (isMoveKeyPress && tranform && !isAiming)
{
Quaternion currentRotation = tranform.LocalRotation;
if (currentState == RaccoonStates.WALKING || currentState == RaccoonStates.RUNNING)
{
Quaternion targetRotation = Quaternion.LookRotation(poitionToLookAt, new Vector3(0.0f, 1.0f, 0.0f));
Quaternion targetRotation = Quaternion.LookRotation(new Vector3(axisMove.x, 0.0f, axisMove.y), new Vector3(0.0f, 1.0f, 0.0f));
tranform.LocalRotation = Quaternion.Slerp(currentRotation, targetRotation, rotationFactorPerFrame * (float)Time.DeltaTime);
}
else if (camArm && tranform && isAiming)
{
Quaternion currentRotation = tranform.LocalRotation;
Quaternion targetRotation = Quaternion.Euler(0.0f, SHADE.Math.DegreesToRadians(camArm.Yaw + 180.0f), 0.0f);
tranform.LocalRotation = Quaternion.Slerp(currentRotation, targetRotation, rotationFactorPerFrame * (float)Time.DeltaTime);
}
}

View File

@ -33,8 +33,6 @@ namespace SHADE_Scripting
}
protected override void update()
{
if (Input.GetMouseButton(Input.MouseCode.RightButton))
{
CameraArm arm = GetComponent<CameraArm>();
if (arm)
@ -51,8 +49,6 @@ namespace SHADE_Scripting
{
arm.Pitch = 0;
}
}
}
}

View File

@ -1,3 +1,3 @@
Name: UT_PlayerCaughtState
ID: 152856879
ID: 153166405
Type: 9

View File

@ -13,9 +13,15 @@ public class Item : Script
public ItemCategory currCategory;
private RigidBody rb;
private Collider collider;
protected override void awake()
{
collider = GetComponent<Collider>();
if (collider)
{
collider.GetCollisionShape(0).Density = 1;
}
rb = GetComponent<RigidBody>();
if (rb)
{