fixed player throwing
added item script player jump is now affected by item weight
This commit is contained in:
parent
3b90c84a85
commit
d6804c09f4
|
@ -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
|
||||
{
|
||||
private PlayerController pc;
|
||||
public GameObject item;
|
||||
public Vector3 throwForce = new Vector3(200.0f, 300.0f, 200.0f);
|
||||
public GameObject item;
|
||||
private PlayerController pc;
|
||||
private Camera cam;
|
||||
private Transform itemTransform;
|
||||
private RigidBody itemRidibody;
|
||||
private Transform raccoonHoldLocation;
|
||||
|
@ -23,40 +24,35 @@ public class PickAndThrow : Script
|
|||
Debug.Log("CHILD EMPTY");
|
||||
else
|
||||
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()
|
||||
{
|
||||
if (!pc.isMoveKeyPress)
|
||||
if (cam == null)
|
||||
cam = GetComponentInChildren<Camera>();
|
||||
else if (cam != null)
|
||||
{
|
||||
if (pc.xAxisMove != 0)
|
||||
{
|
||||
lastXDir = pc.xAxisMove;
|
||||
lastZDir = 0.0f;
|
||||
}
|
||||
if (pc.zAxisMove != 0)
|
||||
{
|
||||
lastXDir = 0.0f;
|
||||
lastZDir = pc.zAxisMove;
|
||||
}
|
||||
Vector3 camerAixs = cam.GetForward();
|
||||
camerAixs.y = 0;
|
||||
camerAixs.Normalise();
|
||||
lastXDir = camerAixs.x;
|
||||
lastZDir = camerAixs.z;
|
||||
}
|
||||
else
|
||||
|
||||
if (item.GetScript<Item>() != null && itemTransform == null && itemRidibody == null)
|
||||
{
|
||||
lastXDir = pc.xAxisMove;
|
||||
lastZDir = pc.zAxisMove;
|
||||
itemTransform = item.GetComponent<Transform>();
|
||||
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))
|
||||
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;
|
||||
itemRidibody.IsGravityEnabled = false;
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue