Merge branch 'main' into SP3-13-Assets-Manager
This commit is contained in:
commit
f2b589071c
|
@ -182,6 +182,7 @@ namespace Sandbox
|
||||||
scriptEngine->AddScript(racoon, "PickAndThrow");
|
scriptEngine->AddScript(racoon, "PickAndThrow");
|
||||||
scriptEngine->AddScript(racoonCamera, "ThirdPersonCamera");
|
scriptEngine->AddScript(racoonCamera, "ThirdPersonCamera");
|
||||||
scriptEngine->AddScript(AI, "AIPrototype");
|
scriptEngine->AddScript(AI, "AIPrototype");
|
||||||
|
scriptEngine->AddScript(item, "Item");
|
||||||
|
|
||||||
auto raccoonShowcase = SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent>();
|
auto raccoonShowcase = SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent>();
|
||||||
auto& renderableShowcase = *SHComponentManager::GetComponent_s<SHRenderable>(raccoonShowcase);
|
auto& renderableShowcase = *SHComponentManager::GetComponent_s<SHRenderable>(raccoonShowcase);
|
||||||
|
|
|
@ -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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,9 +4,10 @@ using static PlayerController;
|
||||||
|
|
||||||
public class PickAndThrow : Script
|
public class PickAndThrow : Script
|
||||||
{
|
{
|
||||||
private PlayerController pc;
|
public Vector3 throwForce = new Vector3(100.0f, 200.0f, 100.0f);
|
||||||
public GameObject item;
|
public GameObject item;
|
||||||
public Vector3 throwForce = new Vector3(200.0f, 300.0f, 200.0f);
|
private PlayerController pc;
|
||||||
|
private Camera cam;
|
||||||
private Transform itemTransform;
|
private Transform itemTransform;
|
||||||
private RigidBody itemRidibody;
|
private RigidBody itemRidibody;
|
||||||
private Transform raccoonHoldLocation;
|
private Transform raccoonHoldLocation;
|
||||||
|
@ -23,40 +24,35 @@ public class PickAndThrow : Script
|
||||||
Debug.Log("CHILD EMPTY");
|
Debug.Log("CHILD EMPTY");
|
||||||
else
|
else
|
||||||
raccoonHoldLocation.LocalPosition = new Vector3(0.0f, 1.0f, 0.0f);
|
raccoonHoldLocation.LocalPosition = new Vector3(0.0f, 1.0f, 0.0f);
|
||||||
|
|
||||||
itemTransform = item.GetComponent<Transform>();
|
|
||||||
if (itemTransform == null)
|
|
||||||
Debug.Log("Item transform EMPTY");
|
|
||||||
|
|
||||||
itemRidibody = item.GetComponent<RigidBody>();
|
|
||||||
if (itemRidibody == null)
|
|
||||||
Debug.Log("Item rb EMPTY");
|
|
||||||
}
|
}
|
||||||
protected override void update()
|
protected override void update()
|
||||||
{
|
{
|
||||||
if (!pc.isMoveKeyPress)
|
if (cam == null)
|
||||||
|
cam = GetComponentInChildren<Camera>();
|
||||||
|
else if (cam != null)
|
||||||
{
|
{
|
||||||
if (pc.xAxisMove != 0)
|
Vector3 camerAixs = cam.GetForward();
|
||||||
{
|
camerAixs.y = 0;
|
||||||
lastXDir = pc.xAxisMove;
|
camerAixs.Normalise();
|
||||||
lastZDir = 0.0f;
|
lastXDir = camerAixs.x;
|
||||||
}
|
lastZDir = camerAixs.z;
|
||||||
if (pc.zAxisMove != 0)
|
|
||||||
{
|
|
||||||
lastXDir = 0.0f;
|
|
||||||
lastZDir = pc.zAxisMove;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (item.GetScript<Item>() != null && itemTransform == null && itemRidibody == null)
|
||||||
{
|
{
|
||||||
lastXDir = pc.xAxisMove;
|
itemTransform = item.GetComponent<Transform>();
|
||||||
lastZDir = pc.zAxisMove;
|
if (itemTransform == null)
|
||||||
|
Debug.Log("Item transform EMPTY");
|
||||||
|
|
||||||
|
itemRidibody = item.GetComponent<RigidBody>();
|
||||||
|
if (itemRidibody == null)
|
||||||
|
Debug.Log("Item rb EMPTY");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pc != null && inRange && !pc.holdItem && Input.GetKey(Input.KeyCode.E))
|
if (pc != null && inRange && !pc.holdItem && Input.GetKey(Input.KeyCode.E))
|
||||||
pc.holdItem = true;
|
pc.holdItem = true;
|
||||||
|
|
||||||
if (pc != null && itemRidibody != null && itemTransform!= null && pc.holdItem)
|
if (pc != null && itemRidibody != null && itemTransform != null && pc.holdItem)
|
||||||
{
|
{
|
||||||
itemTransform.LocalPosition = raccoonHoldLocation.GlobalPosition;
|
itemTransform.LocalPosition = raccoonHoldLocation.GlobalPosition;
|
||||||
itemRidibody.IsGravityEnabled = false;
|
itemRidibody.IsGravityEnabled = false;
|
||||||
|
@ -66,13 +62,13 @@ public class PickAndThrow : Script
|
||||||
if (Input.GetMouseButtonDown(Input.MouseCode.LeftButton))
|
if (Input.GetMouseButtonDown(Input.MouseCode.LeftButton))
|
||||||
{
|
{
|
||||||
pc.holdItem = false;
|
pc.holdItem = 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;
|
||||||
Debug.Log($"x: {itemRidibody.LinearVelocity.x} z: {itemRidibody.LinearVelocity.z}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(!pc.holdItem)
|
else if(!pc.holdItem && itemRidibody != null)
|
||||||
itemRidibody.IsGravityEnabled = true;
|
itemRidibody.IsGravityEnabled = true;
|
||||||
}
|
}
|
||||||
protected override void onCollisionEnter(CollisionInfo info)
|
protected override void onCollisionEnter(CollisionInfo info)
|
||||||
|
@ -80,20 +76,21 @@ public class PickAndThrow : Script
|
||||||
}
|
}
|
||||||
protected override void onTriggerEnter(CollisionInfo info)
|
protected override void onTriggerEnter(CollisionInfo info)
|
||||||
{
|
{
|
||||||
Debug.Log("ENTER");
|
//Debug.Log("ENTER");
|
||||||
if (info.GameObject == item && !pc.holdItem)
|
if (info.GameObject.GetScript<Item>() != null && !pc.holdItem)
|
||||||
{
|
{
|
||||||
|
item = info.GameObject;
|
||||||
inRange = true;
|
inRange = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected override void onTriggerStay(CollisionInfo info)
|
protected override void onTriggerStay(CollisionInfo info)
|
||||||
{
|
{
|
||||||
Debug.Log("STAY");
|
//Debug.Log("STAY");
|
||||||
}
|
}
|
||||||
protected override void onTriggerExit(CollisionInfo info)
|
protected override void onTriggerExit(CollisionInfo info)
|
||||||
{
|
{
|
||||||
Debug.Log("EXIT");
|
//Debug.Log("EXIT");
|
||||||
if (info.GameObject == item && !pc.holdItem)
|
if (info.GameObject.GetScript<Item>() != null && !pc.holdItem)
|
||||||
{
|
{
|
||||||
inRange = false;
|
inRange = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
using SHADE;
|
using SHADE;
|
||||||
using System;
|
using System;
|
||||||
|
using static Item;
|
||||||
//in air controls?
|
|
||||||
|
|
||||||
public class PlayerController : Script
|
public class PlayerController : Script
|
||||||
{
|
{
|
||||||
|
@ -19,6 +18,7 @@ public class PlayerController : Script
|
||||||
public RigidBody rb;
|
public RigidBody rb;
|
||||||
private Transform tranform;
|
private Transform tranform;
|
||||||
private Camera cam;
|
private Camera cam;
|
||||||
|
private PickAndThrow pat;
|
||||||
|
|
||||||
//to be remove
|
//to be remove
|
||||||
public float drag = 2.0f;
|
public float drag = 2.0f;
|
||||||
|
@ -68,13 +68,24 @@ public class PlayerController : Script
|
||||||
private float gravity = -9.8f;
|
private float gravity = -9.8f;
|
||||||
private float groundGravity = -0.5f;
|
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) { }
|
public PlayerController(GameObject gameObj) : base(gameObj) { }
|
||||||
|
|
||||||
protected override void awake()
|
protected override void awake()
|
||||||
{
|
{
|
||||||
|
//default setup
|
||||||
isMoveKeyPress = false;
|
isMoveKeyPress = false;
|
||||||
holdItem = false;
|
holdItem = false;
|
||||||
|
|
||||||
|
//Jump setup
|
||||||
|
float timeToApex = maxJumpTime / 2;
|
||||||
|
gravity = (-2 * maxJumpHeight) / MathF.Pow(timeToApex, 2);
|
||||||
|
initialJumpVel = (2 * maxJumpHeight) / timeToApex;
|
||||||
|
|
||||||
//rigidbody check
|
//rigidbody check
|
||||||
rb = GetComponent<RigidBody>();
|
rb = GetComponent<RigidBody>();
|
||||||
if (rb == null)
|
if (rb == null)
|
||||||
|
@ -94,10 +105,10 @@ public class PlayerController : Script
|
||||||
if(tranform == null)
|
if(tranform == null)
|
||||||
Debug.LogError("tranform is NULL!");
|
Debug.LogError("tranform is NULL!");
|
||||||
|
|
||||||
//Jump setup
|
//PickAndThrow checl
|
||||||
float timeToApex = maxJumpTime / 2;
|
pat = GetScript<PickAndThrow>();
|
||||||
gravity = (-2 * maxJumpHeight) / MathF.Pow(timeToApex, 2);
|
if (pat == null)
|
||||||
initialJumpVel = (2 * maxJumpHeight) / timeToApex;
|
Debug.LogError("PickAndThrow is NULL!");
|
||||||
|
|
||||||
//toRemove
|
//toRemove
|
||||||
tranform.LocalPosition = new Vector3(-3.0f, -2.0f, -5.0f);
|
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);
|
tranform.LocalPosition = new Vector3(-3.0f, -2.0f, -5.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GotCaught();
|
||||||
MoveKey();
|
MoveKey();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Debug.Log(currentState.ToString() + " x:" + rb.LinearVelocity.x.ToString() + " y:" + rb.LinearVelocity.y.ToString() + " z:" + rb.LinearVelocity.z.ToString());
|
//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)
|
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)
|
if (isMoveKeyPress)
|
||||||
{
|
{
|
||||||
|
@ -259,6 +272,16 @@ public class PlayerController : Script
|
||||||
currentState = RaccoonStates.JUMP;
|
currentState = RaccoonStates.JUMP;
|
||||||
Vector3 v = rb.LinearVelocity;
|
Vector3 v = rb.LinearVelocity;
|
||||||
v.y = initialJumpVel * 0.5f;
|
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;
|
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)
|
protected override void onCollisionEnter(CollisionInfo info)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue