mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 12:52:07 +01:00
Merge branch 'player-controller'
This commit is contained in:
@@ -26,7 +26,7 @@ Transform:
|
|||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 681358948229890261}
|
m_GameObject: {fileID: 681358948229890261}
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_LocalPosition: {x: 0.3586286, y: -0.5799999, z: -0.03139314}
|
m_LocalPosition: {x: 0, y: -0.5799999, z: 0.27}
|
||||||
m_LocalScale: {x: 0.8, y: 0.2, z: 1}
|
m_LocalScale: {x: 0.8, y: 0.2, z: 1}
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 981273033772084037}
|
m_Father: {fileID: 981273033772084037}
|
||||||
@@ -266,8 +266,8 @@ GameObject:
|
|||||||
- component: {fileID: 320375778840406984}
|
- component: {fileID: 320375778840406984}
|
||||||
- component: {fileID: -4574526707603160507}
|
- component: {fileID: -4574526707603160507}
|
||||||
- component: {fileID: 7273209952621479910}
|
- component: {fileID: 7273209952621479910}
|
||||||
- component: {fileID: 5317111308216027170}
|
|
||||||
- component: {fileID: 4959463831902427506}
|
- component: {fileID: 4959463831902427506}
|
||||||
|
- component: {fileID: 5630859218361338035}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: Player
|
m_Name: Player
|
||||||
m_TagString: Player
|
m_TagString: Player
|
||||||
@@ -304,10 +304,10 @@ CharacterController:
|
|||||||
m_IsTrigger: 0
|
m_IsTrigger: 0
|
||||||
m_Enabled: 1
|
m_Enabled: 1
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Height: 2
|
m_Height: 1.8
|
||||||
m_Radius: 0.5
|
m_Radius: 0.3
|
||||||
m_SlopeLimit: 45
|
m_SlopeLimit: 45
|
||||||
m_StepOffset: 0.1
|
m_StepOffset: 0.2
|
||||||
m_SkinWidth: 0.08
|
m_SkinWidth: 0.08
|
||||||
m_MinMoveDistance: 0.001
|
m_MinMoveDistance: 0.001
|
||||||
m_Center: {x: 0, y: 1, z: 0}
|
m_Center: {x: 0, y: 1, z: 0}
|
||||||
@@ -342,24 +342,16 @@ MonoBehaviour:
|
|||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
syncMode: 0
|
syncMode: 0
|
||||||
syncInterval: 0.1
|
syncInterval: 0.1
|
||||||
playerCamera: {fileID: 6272346181657429396}
|
|
||||||
playerNeck: {fileID: 981273033772084037}
|
|
||||||
mouseSensitivity: 4
|
|
||||||
maxCameraAngle: 90
|
|
||||||
neckStartAngle: 0
|
|
||||||
minCameraAngle: -90
|
|
||||||
neckLength: 0.2
|
|
||||||
mouseSmoothTime: 0.001
|
|
||||||
lockCursor: 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}
|
||||||
groundDistance: 0.4
|
|
||||||
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:
|
||||||
@@ -390,24 +382,6 @@ MonoBehaviour:
|
|||||||
showGizmos: 1
|
showGizmos: 1
|
||||||
showOverlay: 1
|
showOverlay: 1
|
||||||
overlayColor: {r: 0, g: 0, b: 0, a: 0.5}
|
overlayColor: {r: 0, g: 0, b: 0, a: 0.5}
|
||||||
--- !u!114 &5317111308216027170
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 6272346181302961293}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: c2e457ad00c1a044a924a5bc00776df9, type: 3}
|
|
||||||
m_Name:
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
syncMode: 0
|
|
||||||
syncInterval: 0.1
|
|
||||||
isAlive: 0
|
|
||||||
clientId: 0
|
|
||||||
username: Janis
|
|
||||||
usernameTextObj: {fileID: 4824770690127859843}
|
|
||||||
--- !u!114 &4959463831902427506
|
--- !u!114 &4959463831902427506
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -424,6 +398,29 @@ MonoBehaviour:
|
|||||||
syncInterval: 0.1
|
syncInterval: 0.1
|
||||||
color: {r: 1, g: 0, b: 0, a: 0}
|
color: {r: 1, g: 0, b: 0, a: 0}
|
||||||
renderer: {fileID: 8824871639981994016}
|
renderer: {fileID: 8824871639981994016}
|
||||||
|
--- !u!114 &5630859218361338035
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 6272346181302961293}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: a8493f0e2b0d4bd4f98d3cd81c2db5ad, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
syncMode: 0
|
||||||
|
syncInterval: 0.1
|
||||||
|
playerCamera: {fileID: 6272346181657429396}
|
||||||
|
playerNeck: {fileID: 981273033772084037}
|
||||||
|
mouseSensitivity: 4
|
||||||
|
maxCameraAngle: 90
|
||||||
|
neckStartAngle: 0
|
||||||
|
minCameraAngle: -90
|
||||||
|
neckLength: 0.2
|
||||||
|
mouseSmoothTime: 0.001
|
||||||
|
lockCursor: 1
|
||||||
--- !u!1 &6272346181657429393
|
--- !u!1 &6272346181657429393
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -478,7 +475,7 @@ Camera:
|
|||||||
y: 0
|
y: 0
|
||||||
width: 1
|
width: 1
|
||||||
height: 1
|
height: 1
|
||||||
near clip plane: 0.3
|
near clip plane: 0.1
|
||||||
far clip plane: 1000
|
far clip plane: 1000
|
||||||
field of view: 61.4
|
field of view: 61.4
|
||||||
orthographic: 0
|
orthographic: 0
|
||||||
@@ -522,7 +519,7 @@ Transform:
|
|||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 6272346182417644038}
|
m_GameObject: {fileID: 6272346182417644038}
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_LocalPosition: {x: 0, y: -0, z: 0}
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 6272346181302961296}
|
m_Father: {fileID: 6272346181302961296}
|
||||||
@@ -571,7 +568,6 @@ GameObject:
|
|||||||
- component: {fileID: 2458562619286483438}
|
- component: {fileID: 2458562619286483438}
|
||||||
- component: {fileID: 390397068222218691}
|
- component: {fileID: 390397068222218691}
|
||||||
- component: {fileID: 8824871639981994016}
|
- component: {fileID: 8824871639981994016}
|
||||||
- component: {fileID: 5472825146870239901}
|
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: Capsule
|
m_Name: Capsule
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
@@ -608,7 +604,7 @@ MeshRenderer:
|
|||||||
m_PrefabInstance: {fileID: 0}
|
m_PrefabInstance: {fileID: 0}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 8690889598169456425}
|
m_GameObject: {fileID: 8690889598169456425}
|
||||||
m_Enabled: 1
|
m_Enabled: 0
|
||||||
m_CastShadows: 1
|
m_CastShadows: 1
|
||||||
m_ReceiveShadows: 1
|
m_ReceiveShadows: 1
|
||||||
m_DynamicOccludee: 1
|
m_DynamicOccludee: 1
|
||||||
@@ -643,17 +639,3 @@ MeshRenderer:
|
|||||||
m_SortingLayer: 0
|
m_SortingLayer: 0
|
||||||
m_SortingOrder: 0
|
m_SortingOrder: 0
|
||||||
m_AdditionalVertexStreams: {fileID: 0}
|
m_AdditionalVertexStreams: {fileID: 0}
|
||||||
--- !u!136 &5472825146870239901
|
|
||||||
CapsuleCollider:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 8690889598169456425}
|
|
||||||
m_Material: {fileID: 0}
|
|
||||||
m_IsTrigger: 0
|
|
||||||
m_Enabled: 1
|
|
||||||
m_Radius: 0.5
|
|
||||||
m_Height: 2
|
|
||||||
m_Direction: 1
|
|
||||||
m_Center: {x: 0, y: 0, z: 0}
|
|
||||||
|
|||||||
@@ -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}
|
||||||
|
|||||||
@@ -8,42 +8,30 @@ using Mirror;
|
|||||||
|
|
||||||
public class PlayerController : NetworkBehaviour
|
public class PlayerController : NetworkBehaviour
|
||||||
{
|
{
|
||||||
[Header("Mouse Look")]
|
|
||||||
[SerializeField] private Transform playerCamera = null;
|
|
||||||
[SerializeField] private Transform playerNeck = null;
|
|
||||||
[SerializeField] private float mouseSensitivity = 4.0f;
|
|
||||||
|
|
||||||
[SerializeField] private float maxCameraAngle = -90f;
|
|
||||||
[SerializeField] private float neckStartAngle = 0f;
|
|
||||||
[SerializeField] private float minCameraAngle = 90f;
|
|
||||||
|
|
||||||
[SerializeField] private float neckLength = 0.2f;
|
|
||||||
[SerializeField] [Range(0.0f, 0.5f)] private float mouseSmoothTime = 0.001f;
|
|
||||||
[SerializeField] private bool lockCursor = true;
|
|
||||||
|
|
||||||
[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 moveDirection;
|
||||||
|
|
||||||
[Header("Ground Check")]
|
[Header("Ground Check")]
|
||||||
[SerializeField] private Transform groundCheck;
|
[SerializeField] private Transform groundCheck;
|
||||||
[SerializeField] private float groundDistance = 0.4f;
|
|
||||||
[SerializeField] private LayerMask groundMask;
|
[SerializeField] private LayerMask groundMask;
|
||||||
|
|
||||||
|
[Header("Ground Angle")]
|
||||||
|
[SerializeField] private float groundAngle;
|
||||||
|
[SerializeField] private float moveGroundAngle;
|
||||||
|
|
||||||
public bool isGrounded;
|
public bool isGrounded;
|
||||||
private float fullPitch = 0f;
|
|
||||||
private float cameraPitch = 0f;
|
|
||||||
private float neckPitch = 0f;
|
|
||||||
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 Vector2 currentMouseDelta = Vector2.zero;
|
|
||||||
private Vector2 currentMouseDeltaVelocity = Vector2.zero;
|
|
||||||
|
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
@@ -51,54 +39,57 @@ public class PlayerController : NetworkBehaviour
|
|||||||
if (isLocalPlayer)
|
if (isLocalPlayer)
|
||||||
{
|
{
|
||||||
controller = GetComponent<CharacterController>();
|
controller = GetComponent<CharacterController>();
|
||||||
if (lockCursor)
|
|
||||||
{
|
|
||||||
Cursor.lockState = CursorLockMode.Locked;
|
|
||||||
Cursor.visible = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
playerCamera.gameObject.SetActive(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if (!isLocalPlayer) return;
|
if (isLocalPlayer)
|
||||||
|
{
|
||||||
UpdateMouseLook();
|
Grounded();
|
||||||
Grounded();
|
CheckGoundAngle();
|
||||||
UpdateMovement();
|
UpdateMovement();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
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, groundDistance, groundMask);
|
isGrounded = Physics.CheckSphere(groundCheck.position + new Vector3(0, GetComponent<CharacterController>().radius - 0.1f, 0),GetComponent<CharacterController>().radius + 0.0f, groundMask);
|
||||||
}
|
}
|
||||||
private void UpdateMouseLook()
|
|
||||||
|
public bool isMoving()
|
||||||
{
|
{
|
||||||
Vector2 targetMouseDelta = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y")); //Get the axis of the mouse
|
if (velocity.x == 0 && velocity.y == 0 && velocity.z == 0) return true;
|
||||||
|
else return false;
|
||||||
currentMouseDelta = Vector2.SmoothDamp(currentMouseDelta, targetMouseDelta, ref currentMouseDeltaVelocity, mouseSmoothTime);
|
|
||||||
fullPitch -= currentMouseDelta.y * mouseSensitivity;
|
|
||||||
fullPitch = Mathf.Clamp(fullPitch,-maxCameraAngle,-minCameraAngle);
|
|
||||||
|
|
||||||
if (fullPitch >= neckStartAngle) {
|
|
||||||
playerNeck.localEulerAngles = Vector3.right * (fullPitch - neckStartAngle);
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
playerCamera.localEulerAngles = Vector3.right * fullPitch;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
playerCamera.position = playerNeck.position;
|
|
||||||
playerCamera.position += playerNeck.up * neckLength;
|
|
||||||
|
|
||||||
transform.Rotate(Vector3.up * currentMouseDelta.x * mouseSensitivity); //Rotate the hole player if looked sideways (Rotates the player left and right)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CheckGoundAngle()
|
||||||
|
{
|
||||||
|
//Check every frame if the player stands on the ground
|
||||||
|
RaycastHit hit;
|
||||||
|
if (Physics.Raycast(groundCheck.position + new Vector3(0, 0.4f, 0), Vector3.down, out hit))
|
||||||
|
{
|
||||||
|
moveDirection = Quaternion.Euler(0, transform.eulerAngles.y + 90f, 0) * inputDirection;
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
Gizmos.color = Color.red;
|
||||||
|
Gizmos.DrawRay(new Ray(transform.position, moveDirection * 50));
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateMovement()
|
private void UpdateMovement()
|
||||||
{
|
{
|
||||||
//Grounded
|
//Grounded
|
||||||
@@ -110,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 targetDir = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); //Get Inputs
|
inputDirection = new Vector3(Input.GetAxisRaw("Horizontal"),0, Input.GetAxisRaw("Vertical")); //Get Inputs
|
||||||
targetDir.Normalize(); //Damit schr<68>g laufen nicht schneller ist
|
inputDirection.Normalize(); //Damit schr<68>g laufen nicht schneller ist
|
||||||
|
|
||||||
currentDir = Vector2.SmoothDamp(currentDir, targetDir, 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);
|
||||||
|
|
||||||
|
|||||||
82
Assets/Scripts/Player/PlayerMouseLook.cs
Normal file
82
Assets/Scripts/Player/PlayerMouseLook.cs
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using Mirror;
|
||||||
|
|
||||||
|
public class PlayerMouseLook : NetworkBehaviour
|
||||||
|
{
|
||||||
|
[Header("Mouse Look")]
|
||||||
|
[SerializeField] private Transform playerCamera = null;
|
||||||
|
[SerializeField] private Transform playerNeck = null;
|
||||||
|
[SerializeField] private float mouseSensitivity = 4.0f;
|
||||||
|
|
||||||
|
[SerializeField] private float maxCameraAngle = 90f;
|
||||||
|
[SerializeField] private float neckStartAngle = 0f;
|
||||||
|
[SerializeField] private float minCameraAngle = -90f;
|
||||||
|
|
||||||
|
[SerializeField] private float neckLength = 0.2f;
|
||||||
|
[SerializeField] [Range(0.0f, 0.5f)] private float mouseSmoothTime = 0.001f;
|
||||||
|
[SerializeField] private bool lockCursor = true;
|
||||||
|
|
||||||
|
private float fullPitch = 0f;
|
||||||
|
private float cameraPitch = 0f;
|
||||||
|
private float neckPitch = 0f;
|
||||||
|
private float velocityY = 0.0f;
|
||||||
|
private CharacterController controller;
|
||||||
|
|
||||||
|
private Vector2 currentMouseDelta = Vector2.zero;
|
||||||
|
private Vector2 currentMouseDeltaVelocity = Vector2.zero;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
if (isLocalPlayer)
|
||||||
|
{
|
||||||
|
controller = GetComponent<CharacterController>();
|
||||||
|
|
||||||
|
playerCamera.gameObject.SetActive(true);
|
||||||
|
|
||||||
|
if (lockCursor)
|
||||||
|
{
|
||||||
|
Cursor.lockState = CursorLockMode.Locked;
|
||||||
|
Cursor.visible = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
if (isLocalPlayer)
|
||||||
|
{
|
||||||
|
UpdateMouseLook();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateMouseLook()
|
||||||
|
{
|
||||||
|
Vector2 targetMouseDelta = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y")); //Get the axis of the mouse
|
||||||
|
|
||||||
|
currentMouseDelta = Vector2.SmoothDamp(currentMouseDelta, targetMouseDelta, ref currentMouseDeltaVelocity, mouseSmoothTime);
|
||||||
|
fullPitch -= currentMouseDelta.y * mouseSensitivity;
|
||||||
|
fullPitch = Mathf.Clamp(fullPitch, -maxCameraAngle, -minCameraAngle);
|
||||||
|
|
||||||
|
if (fullPitch >= neckStartAngle)
|
||||||
|
{
|
||||||
|
playerNeck.localEulerAngles = Vector3.right * (fullPitch - neckStartAngle);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
playerCamera.localEulerAngles = Vector3.right * fullPitch;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
playerCamera.position = playerNeck.position;
|
||||||
|
playerCamera.position += playerNeck.up * neckLength;
|
||||||
|
|
||||||
|
transform.Rotate(Vector3.up * currentMouseDelta.x * mouseSensitivity); //Rotate the hole player if looked sideways (Rotates the player left and right)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
11
Assets/Scripts/Player/PlayerMouseLook.cs.meta
Normal file
11
Assets/Scripts/Player/PlayerMouseLook.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a8493f0e2b0d4bd4f98d3cd81c2db5ad
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
13
UserSettings/Search.index
Normal file
13
UserSettings/Search.index
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "Assets",
|
||||||
|
"roots": ["Assets"],
|
||||||
|
"includes": [],
|
||||||
|
"excludes": ["Temp/", "External/"],
|
||||||
|
"options": {
|
||||||
|
"types": true,
|
||||||
|
"properties": false,
|
||||||
|
"extended": false,
|
||||||
|
"dependencies": false
|
||||||
|
},
|
||||||
|
"baseScore": 999
|
||||||
|
}
|
||||||
@@ -1 +1,53 @@
|
|||||||
{}
|
trackSelection = true
|
||||||
|
fetchPreview = true
|
||||||
|
wantsMore = false
|
||||||
|
keepOpen = false
|
||||||
|
queryFolder = "Assets"
|
||||||
|
onBoardingDoNotAskAgain = true
|
||||||
|
showPackageIndexes = false
|
||||||
|
showStatusBar = false
|
||||||
|
scopes = {
|
||||||
|
}
|
||||||
|
providers = {
|
||||||
|
asset = {
|
||||||
|
active = true
|
||||||
|
priority = 25
|
||||||
|
defaultAction = null
|
||||||
|
}
|
||||||
|
store = {
|
||||||
|
active = true
|
||||||
|
priority = 100
|
||||||
|
defaultAction = null
|
||||||
|
}
|
||||||
|
find = {
|
||||||
|
active = true
|
||||||
|
priority = 25
|
||||||
|
defaultAction = null
|
||||||
|
}
|
||||||
|
log = {
|
||||||
|
active = false
|
||||||
|
priority = 210
|
||||||
|
defaultAction = null
|
||||||
|
}
|
||||||
|
packages = {
|
||||||
|
active = true
|
||||||
|
priority = 90
|
||||||
|
defaultAction = null
|
||||||
|
}
|
||||||
|
scene = {
|
||||||
|
active = true
|
||||||
|
priority = 50
|
||||||
|
defaultAction = null
|
||||||
|
}
|
||||||
|
query = {
|
||||||
|
active = true
|
||||||
|
priority = 100
|
||||||
|
defaultAction = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
recentSearches = [
|
||||||
|
]
|
||||||
|
searchItemFavorites = [
|
||||||
|
]
|
||||||
|
savedSearchesSortOrder = 0
|
||||||
|
showSavedSearchPanel = false
|
||||||
Reference in New Issue
Block a user