mirror of
https://github.com/DerTyp7/fps-citybuild-unity.git
synced 2025-10-29 20:22:08 +01:00
PlayerController Slope fix
Fixing that the player can walk over any slope
This commit is contained in:
@@ -473,6 +473,102 @@ PrefabInstance:
|
|||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
m_RemovedComponents: []
|
m_RemovedComponents: []
|
||||||
m_SourcePrefab: {fileID: 100100000, guid: 613866d46c759a848b2a462973745a74, type: 3}
|
m_SourcePrefab: {fileID: 100100000, guid: 613866d46c759a848b2a462973745a74, type: 3}
|
||||||
|
--- !u!1 &597571703
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 597571707}
|
||||||
|
- component: {fileID: 597571706}
|
||||||
|
- component: {fileID: 597571705}
|
||||||
|
- component: {fileID: 597571704}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: Cube
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!65 &597571704
|
||||||
|
BoxCollider:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 597571703}
|
||||||
|
m_Material: {fileID: 0}
|
||||||
|
m_IsTrigger: 0
|
||||||
|
m_Enabled: 1
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Size: {x: 1, y: 1, z: 1}
|
||||||
|
m_Center: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!23 &597571705
|
||||||
|
MeshRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 597571703}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_CastShadows: 1
|
||||||
|
m_ReceiveShadows: 1
|
||||||
|
m_DynamicOccludee: 1
|
||||||
|
m_StaticShadowCaster: 0
|
||||||
|
m_MotionVectors: 1
|
||||||
|
m_LightProbeUsage: 1
|
||||||
|
m_ReflectionProbeUsage: 1
|
||||||
|
m_RayTracingMode: 2
|
||||||
|
m_RayTraceProcedural: 0
|
||||||
|
m_RenderingLayerMask: 1
|
||||||
|
m_RendererPriority: 0
|
||||||
|
m_Materials:
|
||||||
|
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
|
||||||
|
m_StaticBatchInfo:
|
||||||
|
firstSubMesh: 0
|
||||||
|
subMeshCount: 0
|
||||||
|
m_StaticBatchRoot: {fileID: 0}
|
||||||
|
m_ProbeAnchor: {fileID: 0}
|
||||||
|
m_LightProbeVolumeOverride: {fileID: 0}
|
||||||
|
m_ScaleInLightmap: 1
|
||||||
|
m_ReceiveGI: 1
|
||||||
|
m_PreserveUVs: 0
|
||||||
|
m_IgnoreNormalsForChartDetection: 0
|
||||||
|
m_ImportantGI: 0
|
||||||
|
m_StitchLightmapSeams: 1
|
||||||
|
m_SelectedEditorRenderState: 3
|
||||||
|
m_MinimumChartSize: 4
|
||||||
|
m_AutoUVMaxDistance: 0.5
|
||||||
|
m_AutoUVMaxAngle: 89
|
||||||
|
m_LightmapParameters: {fileID: 0}
|
||||||
|
m_SortingLayerID: 0
|
||||||
|
m_SortingLayer: 0
|
||||||
|
m_SortingOrder: 0
|
||||||
|
m_AdditionalVertexStreams: {fileID: 0}
|
||||||
|
--- !u!33 &597571706
|
||||||
|
MeshFilter:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 597571703}
|
||||||
|
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
|
--- !u!4 &597571707
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 597571703}
|
||||||
|
m_LocalRotation: {x: 0.39065084, y: 0, z: 0, w: 0.920539}
|
||||||
|
m_LocalPosition: {x: -1.1113024, y: 21.66, z: -7.89}
|
||||||
|
m_LocalScale: {x: 6.04, y: 0.35, z: -10.45}
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_RootOrder: 7
|
||||||
|
m_LocalEulerAnglesHint: {x: 45.99, y: 0, z: 0}
|
||||||
--- !u!1 &705507993
|
--- !u!1 &705507993
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
[SerializeField] private Transform groundCheck;
|
[SerializeField] private Transform groundCheck;
|
||||||
[SerializeField] private float groundDistance = 0.4f;
|
[SerializeField] private float groundDistance = 0.4f;
|
||||||
[SerializeField] private LayerMask groundMask;
|
[SerializeField] private LayerMask groundMask;
|
||||||
|
[SerializeField] private float maxWalkebleAngle = 45f;
|
||||||
|
|
||||||
public bool isSprinting = false;
|
public bool isSprinting = false;
|
||||||
public bool isSneaking = false;
|
public bool isSneaking = false;
|
||||||
@@ -27,10 +28,13 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
private bool isJumpSprinting = false;
|
private bool isJumpSprinting = false;
|
||||||
float x;
|
float x;
|
||||||
float z;
|
float z;
|
||||||
|
float angle;
|
||||||
|
|
||||||
Vector3 movement;
|
Vector3 movement;
|
||||||
|
Vector3 moveDirection;
|
||||||
|
Vector3 angleDir;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
@@ -54,6 +58,20 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
{
|
{
|
||||||
//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, groundDistance, groundMask);
|
||||||
|
RaycastHit hit;
|
||||||
|
|
||||||
|
if (Physics.Raycast(gameObject.transform.position, Vector3.down, out hit)) {
|
||||||
|
Vector3 t = hit.normal;
|
||||||
|
angle = Vector3.Angle(t,Vector3.up);
|
||||||
|
angleDir = new Vector3(t.x,0,t.z).normalized;
|
||||||
|
|
||||||
|
}
|
||||||
|
Vector3 g = angleDir - Vector3.forward;
|
||||||
|
Debug.Log(g.magnitude);
|
||||||
|
if (angle > maxWalkebleAngle && !(g.magnitude > 1))
|
||||||
|
{
|
||||||
|
isGrounded = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (isGrounded)
|
if (isGrounded)
|
||||||
{
|
{
|
||||||
@@ -89,7 +107,7 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
|
|
||||||
x = Input.GetAxis("Horizontal");
|
x = Input.GetAxis("Horizontal");
|
||||||
z = Input.GetAxis("Vertical");
|
z = Input.GetAxis("Vertical");
|
||||||
|
moveDirection.Set(x,0,z);
|
||||||
movement = x * modifiedSpeed * transform.right + new Vector3(0, rb.velocity.y, 0) + z * modifiedSpeed * transform.forward;
|
movement = x * modifiedSpeed * transform.right + new Vector3(0, rb.velocity.y, 0) + z * modifiedSpeed * transform.forward;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user