aiming is done in player

This commit is contained in:
Glence 2022-11-21 00:12:09 +08:00
parent 8107c92754
commit 293cc586d1
6 changed files with 140 additions and 102 deletions

View File

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

View File

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

View File

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

View File

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

View File

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