Merge branch 'main' into SP3-13-Assets-Manager

This commit is contained in:
Xiao Qi 2022-11-04 17:49:43 +08:00
commit f2b589071c
4 changed files with 88 additions and 40 deletions

View File

@ -182,6 +182,7 @@ namespace Sandbox
scriptEngine->AddScript(racoon, "PickAndThrow");
scriptEngine->AddScript(racoonCamera, "ThirdPersonCamera");
scriptEngine->AddScript(AI, "AIPrototype");
scriptEngine->AddScript(item, "Item");
auto raccoonShowcase = SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent>();
auto& renderableShowcase = *SHComponentManager::GetComponent_s<SHRenderable>(raccoonShowcase);

18
TempScriptsFolder/Item.cs Normal file
View File

@ -0,0 +1,18 @@
using SHADE;
using System;
public class Item : Script
{
public enum ItemCategory
{
LIGHT,
MEDIUM,
HEAVY
}
public ItemCategory currCategory;
public Item(GameObject gameObj) : base(gameObj) { }
protected override void awake()
{
}
}

View File

@ -4,9 +4,10 @@ using static PlayerController;
public class PickAndThrow : Script
{
private PlayerController pc;
public Vector3 throwForce = new Vector3(100.0f, 200.0f, 100.0f);
public GameObject item;
public Vector3 throwForce = new Vector3(200.0f, 300.0f, 200.0f);
private PlayerController pc;
private Camera cam;
private Transform itemTransform;
private RigidBody itemRidibody;
private Transform raccoonHoldLocation;
@ -23,7 +24,22 @@ public class PickAndThrow : Script
Debug.Log("CHILD EMPTY");
else
raccoonHoldLocation.LocalPosition = new Vector3(0.0f, 1.0f, 0.0f);
}
protected override void update()
{
if (cam == null)
cam = GetComponentInChildren<Camera>();
else if (cam != null)
{
Vector3 camerAixs = cam.GetForward();
camerAixs.y = 0;
camerAixs.Normalise();
lastXDir = camerAixs.x;
lastZDir = camerAixs.z;
}
if (item.GetScript<Item>() != null && itemTransform == null && itemRidibody == null)
{
itemTransform = item.GetComponent<Transform>();
if (itemTransform == null)
Debug.Log("Item transform EMPTY");
@ -32,26 +48,6 @@ public class PickAndThrow : Script
if (itemRidibody == null)
Debug.Log("Item rb EMPTY");
}
protected override void update()
{
if (!pc.isMoveKeyPress)
{
if (pc.xAxisMove != 0)
{
lastXDir = pc.xAxisMove;
lastZDir = 0.0f;
}
if (pc.zAxisMove != 0)
{
lastXDir = 0.0f;
lastZDir = pc.zAxisMove;
}
}
else
{
lastXDir = pc.xAxisMove;
lastZDir = pc.zAxisMove;
}
if (pc != null && inRange && !pc.holdItem && Input.GetKey(Input.KeyCode.E))
pc.holdItem = true;
@ -66,13 +62,13 @@ public class PickAndThrow : Script
if (Input.GetMouseButtonDown(Input.MouseCode.LeftButton))
{
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;
Debug.Log($"x: {itemRidibody.LinearVelocity.x} z: {itemRidibody.LinearVelocity.z}");
}
}
else if(!pc.holdItem)
else if(!pc.holdItem && itemRidibody != null)
itemRidibody.IsGravityEnabled = true;
}
protected override void onCollisionEnter(CollisionInfo info)
@ -80,20 +76,21 @@ public class PickAndThrow : Script
}
protected override void onTriggerEnter(CollisionInfo info)
{
Debug.Log("ENTER");
if (info.GameObject == item && !pc.holdItem)
//Debug.Log("ENTER");
if (info.GameObject.GetScript<Item>() != null && !pc.holdItem)
{
item = info.GameObject;
inRange = true;
}
}
protected override void onTriggerStay(CollisionInfo info)
{
Debug.Log("STAY");
//Debug.Log("STAY");
}
protected override void onTriggerExit(CollisionInfo info)
{
Debug.Log("EXIT");
if (info.GameObject == item && !pc.holdItem)
//Debug.Log("EXIT");
if (info.GameObject.GetScript<Item>() != null && !pc.holdItem)
{
inRange = false;
}

View File

@ -1,7 +1,6 @@
using SHADE;
using System;
//in air controls?
using static Item;
public class PlayerController : Script
{
@ -19,6 +18,7 @@ public class PlayerController : Script
public RigidBody rb;
private Transform tranform;
private Camera cam;
private PickAndThrow pat;
//to be remove
public float drag = 2.0f;
@ -68,13 +68,24 @@ public class PlayerController : Script
private float gravity = -9.8f;
private float groundGravity = -0.5f;
//ItemMultipler==================================================================
public float lightMultiper = 0.75f;
public float mediumMultiper = 0.5f;
public float heavyMultiper = 0.25f;
public PlayerController(GameObject gameObj) : base(gameObj) { }
protected override void awake()
{
//default setup
isMoveKeyPress = false;
holdItem = false;
//Jump setup
float timeToApex = maxJumpTime / 2;
gravity = (-2 * maxJumpHeight) / MathF.Pow(timeToApex, 2);
initialJumpVel = (2 * maxJumpHeight) / timeToApex;
//rigidbody check
rb = GetComponent<RigidBody>();
if (rb == null)
@ -94,10 +105,10 @@ public class PlayerController : Script
if(tranform == null)
Debug.LogError("tranform is NULL!");
//Jump setup
float timeToApex = maxJumpTime / 2;
gravity = (-2 * maxJumpHeight) / MathF.Pow(timeToApex, 2);
initialJumpVel = (2 * maxJumpHeight) / timeToApex;
//PickAndThrow checl
pat = GetScript<PickAndThrow>();
if (pat == null)
Debug.LogError("PickAndThrow is NULL!");
//toRemove
tranform.LocalPosition = new Vector3(-3.0f, -2.0f, -5.0f);
@ -116,9 +127,11 @@ public class PlayerController : Script
tranform.LocalPosition = new Vector3(-3.0f, -2.0f, -5.0f);
}
GotCaught();
MoveKey();
//Debug.Log(currentState.ToString() + " x:" + rb.LinearVelocity.x.ToString() + " y:" + rb.LinearVelocity.y.ToString() + " z:" + rb.LinearVelocity.z.ToString());
}
@ -202,7 +215,7 @@ public class PlayerController : Script
{
if (rb != null)
{
rb.AddForce(new Vector3(moveForce * axisMove.x, 0.0f, moveForce * axisMove.y));
rb.AddForce(new Vector3(axisMove.x, 0.0f,axisMove.y) * moveForce);
if (isMoveKeyPress)
{
@ -259,6 +272,16 @@ public class PlayerController : Script
currentState = RaccoonStates.JUMP;
Vector3 v = rb.LinearVelocity;
v.y = initialJumpVel * 0.5f;
if (pat != null && pat.item.GetScript<Item>() != null && holdItem)
{
Item item = pat.item.GetScript<Item>();
if (item.currCategory == ItemCategory.LIGHT)
v.y *= lightMultiper;
if (item.currCategory == ItemCategory.MEDIUM)
v.y *= mediumMultiper;
if (item.currCategory == ItemCategory.HEAVY)
v.y *= heavyMultiper;
}
rb.LinearVelocity = v;
}
}
@ -319,6 +342,15 @@ public class PlayerController : Script
}
}
private void GotCaught()
{
if (currentState == RaccoonStates.CAUGHT && tranform != null)
{
currentState = RaccoonStates.IDILE;
tranform.LocalPosition = new Vector3(-3.0f, -2.0f, -5.0f);
}
}
protected override void onCollisionEnter(CollisionInfo info)
{
}