mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 20:52:10 +01:00
Ground Angle Check
-Added GroundAngleCheck
This commit is contained in:
@@ -344,12 +344,14 @@ MonoBehaviour:
|
|||||||
syncInterval: 0.1
|
syncInterval: 0.1
|
||||||
walkSpeed: 6
|
walkSpeed: 6
|
||||||
moveSmoothTime: 0.05
|
moveSmoothTime: 0.05
|
||||||
gravity: -13
|
gravity: -10
|
||||||
jumpHeight: 2
|
jumpHeight: 1
|
||||||
groundCheck: {fileID: 6272346182417644039}
|
groundCheck: {fileID: 6272346182417644039}
|
||||||
groundMask:
|
groundMask:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Bits: 64
|
m_Bits: 64
|
||||||
|
groundAngle: 0
|
||||||
|
moveGroundAngle: 0
|
||||||
isGrounded: 0
|
isGrounded: 0
|
||||||
--- !u!114 &7273209952621479910
|
--- !u!114 &7273209952621479910
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
|
|||||||
@@ -621,6 +621,49 @@ PrefabInstance:
|
|||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
m_RemovedComponents: []
|
m_RemovedComponents: []
|
||||||
m_SourcePrefab: {fileID: 100100000, guid: 823e8b39d52b71b4eb5a91dbc8d6d59e, type: 3}
|
m_SourcePrefab: {fileID: 100100000, guid: 823e8b39d52b71b4eb5a91dbc8d6d59e, type: 3}
|
||||||
|
--- !u!1 &897280304
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 897280306}
|
||||||
|
- component: {fileID: 897280305}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: Player Spawn
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!114 &897280305
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 897280304}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 41f84591ce72545258ea98cb7518d8b9, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
--- !u!4 &897280306
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 897280304}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 10.14, y: 2.95154, z: 7.02}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_RootOrder: 6
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!1 &1035340512 stripped
|
--- !u!1 &1035340512 stripped
|
||||||
GameObject:
|
GameObject:
|
||||||
m_CorrespondingSourceObject: {fileID: -208595431880416365, guid: 823e8b39d52b71b4eb5a91dbc8d6d59e, type: 3}
|
m_CorrespondingSourceObject: {fileID: -208595431880416365, guid: 823e8b39d52b71b4eb5a91dbc8d6d59e, type: 3}
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ public class PlayerController : NetworkBehaviour
|
|||||||
|
|
||||||
[Header("Movement")]
|
[Header("Movement")]
|
||||||
[SerializeField] private float walkSpeed = 6.0f;
|
[SerializeField] private float walkSpeed = 6.0f;
|
||||||
[SerializeField][Range(0.0f, 0.5f)] private float moveSmoothTime = 0.05f;
|
[SerializeField][Range(0.0f, 0.5f)] private float moveSmoothTime = 0.001f;
|
||||||
[SerializeField] float gravity = -13.0f;
|
[SerializeField] float gravity = -10.0f;
|
||||||
[SerializeField] private float jumpHeight;
|
[SerializeField] private float jumpHeight;
|
||||||
private Vector3 inputDirection = Vector3.zero;
|
private Vector3 inputDirection = Vector3.zero;
|
||||||
private Vector3 moveDirection;
|
private Vector3 moveDirection;
|
||||||
@@ -22,15 +22,16 @@ public class PlayerController : NetworkBehaviour
|
|||||||
[SerializeField] private LayerMask groundMask;
|
[SerializeField] private LayerMask groundMask;
|
||||||
|
|
||||||
[Header("Ground Angle")]
|
[Header("Ground Angle")]
|
||||||
// [SerializeField] private Transform groundDistance;
|
[SerializeField] private float groundAngle;
|
||||||
|
[SerializeField] private float moveGroundAngle;
|
||||||
|
|
||||||
public bool isGrounded;
|
public bool isGrounded;
|
||||||
private float velocityY = 0.0f;
|
private float velocityY = 0.0f;
|
||||||
private CharacterController controller;
|
private CharacterController controller;
|
||||||
|
|
||||||
private Vector2 currentDir = Vector2.zero;
|
private Vector3 currentDir = Vector3.zero;
|
||||||
private Vector2 currentDirVelocity = Vector2.zero;
|
private Vector3 currentDirVelocity = Vector3.zero;
|
||||||
|
private Vector3 velocity = Vector3.zero;
|
||||||
|
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
@@ -52,18 +53,35 @@ public class PlayerController : NetworkBehaviour
|
|||||||
private void Grounded()
|
private void Grounded()
|
||||||
{
|
{
|
||||||
//Check every frame if the player stands on the ground
|
//Check every frame if the player stands on the ground
|
||||||
isGrounded = Physics.CheckSphere(groundCheck.position + new Vector3(0, GetComponent<CharacterController>().radius - 0.01f, 0),GetComponent<CharacterController>().radius + 0.0f, groundMask);
|
isGrounded = Physics.CheckSphere(groundCheck.position + new Vector3(0, GetComponent<CharacterController>().radius - 0.1f, 0),GetComponent<CharacterController>().radius + 0.0f, groundMask);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool isMoving()
|
||||||
|
{
|
||||||
|
if (velocity.x == 0 && velocity.y == 0 && velocity.z == 0) return true;
|
||||||
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckGoundAngle()
|
private void CheckGoundAngle()
|
||||||
{
|
{
|
||||||
//Check every frame if the player stands on the ground
|
//Check every frame if the player stands on the ground
|
||||||
RaycastHit hit;
|
RaycastHit hit;
|
||||||
if (Physics.Raycast(groundCheck.position + new Vector3(0,0.4f,0),Vector3.down,out hit))
|
if (Physics.Raycast(groundCheck.position + new Vector3(0, 0.4f, 0), Vector3.down, out hit))
|
||||||
{
|
{
|
||||||
Debug.Log(transform.eulerAngles.y);
|
moveDirection = Quaternion.Euler(0, transform.eulerAngles.y + 90f, 0) * inputDirection;
|
||||||
moveDirection = Quaternion.Euler(0, transform.eulerAngles.y + 90, 0) * inputDirection;
|
|
||||||
moveDirection = Vector3.Cross(moveDirection, hit.normal);
|
moveDirection = Vector3.Cross(moveDirection, hit.normal);
|
||||||
|
|
||||||
|
if (isMoving())
|
||||||
|
{
|
||||||
|
moveGroundAngle = -(Vector3.Angle(moveDirection, transform.up) - 90f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
moveGroundAngle = 0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
groundAngle = Vector3.Angle(hit.normal,transform.up);
|
||||||
|
Debug.Log(moveGroundAngle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void OnDrawGizmos()
|
private void OnDrawGizmos()
|
||||||
@@ -83,16 +101,25 @@ public class PlayerController : NetworkBehaviour
|
|||||||
if (Input.GetButtonDown("Jump") && isGrounded)
|
if (Input.GetButtonDown("Jump") && isGrounded)
|
||||||
{
|
{
|
||||||
//Debug.Log("Jump");
|
//Debug.Log("Jump");
|
||||||
velocityY += Mathf.Sqrt(jumpHeight * -2f * gravity);
|
velocityY += Mathf.Sqrt(jumpHeight * 4f);
|
||||||
}
|
}
|
||||||
|
|
||||||
inputDirection = new Vector3(Input.GetAxisRaw("Horizontal"),0, Input.GetAxisRaw("Vertical")); //Get Inputs
|
inputDirection = new Vector3(Input.GetAxisRaw("Horizontal"),0, Input.GetAxisRaw("Vertical")); //Get Inputs
|
||||||
inputDirection.Normalize(); //Damit schr<68>g laufen nicht schneller ist
|
inputDirection.Normalize(); //Damit schr<68>g laufen nicht schneller ist
|
||||||
|
|
||||||
currentDir = Vector2.SmoothDamp(currentDir, new Vector2(inputDirection.x,inputDirection.z), ref currentDirVelocity, moveSmoothTime); //Smooth movement change
|
if (isGrounded)
|
||||||
|
{
|
||||||
|
currentDir = moveDirection;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
moveDirection = new Vector3(moveDirection.x, 0, moveDirection.z);
|
||||||
|
currentDir = moveDirection;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentDir = currentDir + new Vector3(0, velocityY, 0);
|
||||||
|
velocity = currentDir * walkSpeed;
|
||||||
|
|
||||||
Vector3 velocity = (transform.forward * currentDir.y + transform.right * currentDir.x) * walkSpeed + (Vector3.up * velocityY);
|
|
||||||
|
|
||||||
controller.Move(velocity * Time.deltaTime);
|
controller.Move(velocity * Time.deltaTime);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user