Created the Inventory Selection Scene

Added an ItemOption Prefab
Created Player Prefab
The player now will get their items in the inventory selection screen
Only within this scene will items be able to be added and removed
Updated player files to check for characterController being enabled
This will make it easier to implement the dual RigidBody system
This commit is contained in:
Melbyj1125
2021-10-14 22:50:44 -05:00
parent c39ffc26c1
commit a42e802ace
21 changed files with 2046 additions and 318 deletions

View File

@@ -48,4 +48,34 @@ public class Item: ScriptableObject {
p.PlayerGrav += playerGravM;
}
}
public void Unequip(PlayerStats p){
if(maxVelM != 0){
p.MaxVel -= maxVelM;
}
if(minVelM != 0){
p.MinVel -= minVelM;
}
if(curVelM != 0){
p.CurVel -= curVelM;
}
if(accM != 0){
p.Acc -= accM;
}
if(jumpPowM != 0){
p.JumpPow -= jumpPowM;
}
if(jumpNumM != 0){
p.JumpNum -= jumpNumM;
}
if(tractionM != 0){
p.Traction -= tractionM;
}
if(kickPowM != 0){
p.KickPow -= kickPowM;
}
if(playerGravM != 0){
p.PlayerGrav -= playerGravM;
}
}
}

View File

@@ -12,8 +12,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d76cac0a7f5ea2a4cadbec8ef3315ec1, type: 3}
m_Name: QuickStandup
m_EditorClassIdentifier:
id: 4
itemName: QuickStandup
id: 1
itemName: Quick Standup
description: Player gets up faster
maxVelM: 0
minVelM: 0

View File

@@ -12,8 +12,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d76cac0a7f5ea2a4cadbec8ef3315ec1, type: 3}
m_Name: RollerSkates
m_EditorClassIdentifier:
id: 1
itemName: RollerSkates
id: 2
itemName: Roller Skates
description: More Slidey But Faster
maxVelM: 15
minVelM: 0

View File

@@ -12,7 +12,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d76cac0a7f5ea2a4cadbec8ef3315ec1, type: 3}
m_Name: Springs
m_EditorClassIdentifier:
id: 2
id: 3
itemName: Springs
description: Jump Higher
maxVelM: 0

View File

@@ -12,9 +12,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d76cac0a7f5ea2a4cadbec8ef3315ec1, type: 3}
m_Name: StrongerKick
m_EditorClassIdentifier:
id: 0
itemName:
description:
id: 4
itemName: Strong Kick
description: Kick Harder
maxVelM: 0
minVelM: 0
curVelM: 0

View File

@@ -12,8 +12,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d76cac0a7f5ea2a4cadbec8ef3315ec1, type: 3}
m_Name: TripleJump
m_EditorClassIdentifier:
id: 3
itemName: TripleJump
id: 5
itemName: Triple Jump
description: Player gets an extra jump but has less jump height
maxVelM: 0
minVelM: 0

View File

@@ -9,39 +9,35 @@ public class PlayerInventory : MonoBehaviour
//Scripts
public PlayerStats pStats;
public InventoryManager invMan;
public bool AddItem(Item item){
items.Add(item);
return true;
void Awake(){
pStats = GetComponent<PlayerStats>();
}
public bool AddSpecialItem<T>(T itemCandidate) { // Unless we don't want the four special items to be handled by inventory/inventory manager?
public void AddItem(Item item){
if(!items.Contains(item)){
Debug.Log("Item Added");
items.Add(item);
item.Equip(pStats);
}
else{
Debug.Log("Item Removed");
RemoveItem(item);
}
}
public void AddSpecialItem<T>(T itemCandidate) { // Unless we don't want the four special items to be handled by inventory/inventory manager?
if (itemCandidate is Item) {
items.Add(itemCandidate as Item);
}
return true;
}
public bool RemoveItem(Item item){
public void RemoveItem(Item item){
if(items.Remove(item)){
return true;
}
return false;
}
void Awake(){
pStats = GetComponent<PlayerStats>();
invMan = GetComponent<InventoryManager>();//////UPDATE WHEN THIS IS NO LONGER ATTACHED TO THE PLAYER
}
void Start(){
AddItem(invMan.ItemList[0]);
AddItem(invMan.ItemList[1]);
foreach (Item item in items){
Debug.Log(item.name);
item.Equip(pStats);
item.Unequip(pStats);
}
}

View File

@@ -64,26 +64,27 @@ public class PlayerMovement : MonoBehaviour
void Awake(){
//Initialize Components
moveController = GetComponent<CharacterController>();
moveController = GetComponentInChildren<CharacterController>();
pStats = GetComponent<PlayerStats>();
Cursor.lockState = CursorLockMode.Locked;
ignoreP = LayerMask.GetMask("Player");
beam = gameObject.AddComponent<LineRenderer>();
beam.startWidth = 0.2f;
beam.endWidth = 0.2f;
beam.enabled = false;
//camera transform
cam = Camera.main;
cam = GetComponent<Camera>();
//Wallrun
wallRun = gameObject.GetComponent<WallRun>();
//wallRun = gameObject.GetComponent<WallRun>();
}
void Start(){
distToGround = GetComponent<Collider>().bounds.extents.y;
Cursor.lockState = CursorLockMode.Locked;
distToGround = GetComponentInChildren<Collider>().bounds.extents.y;
}
@@ -95,16 +96,28 @@ public class PlayerMovement : MonoBehaviour
//Controls for camera
Rotate();
if(moveController.enabled == true){
//if suffiecient impact magnitude is applied then move player
if (impact.magnitude > 0.2F) moveController.Move(impact * Time.deltaTime);
//input controls for movement
InputController();
// consumes the impact energy each cycle:
impact = Vector3.Lerp(impact, Vector3.zero, 5*Time.deltaTime);
//if suffiecient impact magnitude is applied then move player
if (impact.magnitude > 0.2F) moveController.Move(impact * Time.deltaTime);
// consumes the impact energy each cycle:
impact = Vector3.Lerp(impact, Vector3.zero, 5*Time.deltaTime);
Blink();
}
else{
Debug.Log("MoveController is either Disabled or wasn't retrieved correctly");
}
//Checks if player should respawn
Respawn();
Blink();
}
@@ -185,9 +198,9 @@ public class PlayerMovement : MonoBehaviour
//NEEDS TO BE MASSIVELY CHANGE LIKELY USE RAYCAST TO CHECK IF ACTUALLY ON GROUND
//CANNOT USE CHARACTERCONTROLLER.ISGROUNDED IT IS UNRELIABLE
//If grounded no jumps have been used
// if(IsGrounded()){
// curJumpNum = 0;
// }
if(IsGrounded()){
curJumpNum = 0;
}
//If space isn't being pressed then jump is false
if(Input.GetAxis("Jump")==0) jumpPressed = false;
@@ -245,7 +258,6 @@ public class PlayerMovement : MonoBehaviour
{
// Make sure that the ground check distance while already in air is very small, to prevent suddenly snapping to ground
float chosenGroundCheckDistance = isGrounded ? (moveController.skinWidth + groundCheckDistance) : groundCheckDistanceInAir;
// reset values before the ground check
isGrounded = false;
Vector3 groundNormal = Vector3.up;
@@ -253,16 +265,19 @@ public class PlayerMovement : MonoBehaviour
// only try to detect ground if it's been a short amount of time since last jump; otherwise we may snap to the ground instantly after we try jumping
if (Time.time >= lastTimeJumped + jumpGroundingPreventionTime)
{
Debug.Log("detect ground");
// if we're grounded, collect info about the ground normal with a downward capsule cast representing our character capsule
if (Physics.CapsuleCast(GetCapsuleBottomHemisphere(), GetCapsuleTopHemisphere(moveController.height), moveController.radius, Vector3.down, out RaycastHit hit, chosenGroundCheckDistance, groundCheckLayers, QueryTriggerInteraction.Ignore))
{
Debug.Log("Collect info");
// storing the upward direction for the surface found
groundNormal = hit.normal;
// Only consider this a valid ground hit if the ground normal goes in the same direction as the character up
// and if the slope angle is lower than the character controller's limit
if (Vector3.Dot(hit.normal, transform.up) > 0f && IsNormalUnderSlopeLimit(groundNormal))
if (Vector3.Dot(hit.normal, transform.up) > 0.0f && IsNormalUnderSlopeLimit(groundNormal))
{
Debug.Log("isGrounded");
isGrounded = true;
// handle snapping to the ground
@@ -275,6 +290,11 @@ public class PlayerMovement : MonoBehaviour
}
}
//Improved IsGrounded
private bool IsGrounded(){
return Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.1f, ~ignoreP);
}
private bool IsNormalUnderSlopeLimit(Vector3 normal){ // Returns true if the slope angle represented by the given normal is under the slope angle limit of the character controller
return Vector3.Angle(transform.up, normal) <= moveController.slopeLimit;
}