Make importatn repair of moviment
This commit is contained in:
parent
523355cd07
commit
8b31cc457a
@ -121,6 +121,12 @@ NavMeshSettings:
|
||||
debug:
|
||||
m_Flags: 0
|
||||
m_NavMeshData: {fileID: 0}
|
||||
--- !u!1 &97095386 stripped
|
||||
GameObject:
|
||||
m_CorrespondingSourceObject: {fileID: 7801516489048978514, guid: 4f1a4eb0e633f7740b9c4928cf54ce35,
|
||||
type: 3}
|
||||
m_PrefabInstance: {fileID: 7801516488729611279}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
--- !u!1 &490917657
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -561,6 +567,26 @@ PrefabInstance:
|
||||
propertyPath: m_LocalEulerAnglesHint.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7801516488764644388, guid: 4f1a4eb0e633f7740b9c4928cf54ce35,
|
||||
type: 3}
|
||||
propertyPath: jump
|
||||
value: 30
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7801516488764644388, guid: 4f1a4eb0e633f7740b9c4928cf54ce35,
|
||||
type: 3}
|
||||
propertyPath: speed
|
||||
value: 25
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7801516488764644388, guid: 4f1a4eb0e633f7740b9c4928cf54ce35,
|
||||
type: 3}
|
||||
propertyPath: runSpeed
|
||||
value: 50
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7801516488764644388, guid: 4f1a4eb0e633f7740b9c4928cf54ce35,
|
||||
type: 3}
|
||||
propertyPath: playerModel
|
||||
value:
|
||||
objectReference: {fileID: 97095386}
|
||||
- target: {fileID: 7801516488764644390, guid: 4f1a4eb0e633f7740b9c4928cf54ce35,
|
||||
type: 3}
|
||||
propertyPath: m_Name
|
||||
|
@ -5,16 +5,15 @@ using UnityEngine;
|
||||
public class PlayerManager : MonoBehaviour
|
||||
{
|
||||
|
||||
public float speed = 8;
|
||||
public float runSpeed = 20;
|
||||
public float rotateSpeed = 5;
|
||||
public float speed = 25;
|
||||
public float runSpeed = 50;
|
||||
public float mouseSensitive = 100;
|
||||
public float jump = 5;
|
||||
private Vector3 jumpPower = new Vector3();
|
||||
public float jump = 30;
|
||||
public bool onGround = false;
|
||||
private bool run = false;
|
||||
private Camera playerCamera;
|
||||
private Rigidbody rigidBody;
|
||||
public GameObject playerModel;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
@ -30,9 +29,14 @@ public class PlayerManager : MonoBehaviour
|
||||
{
|
||||
Application.Quit(0);
|
||||
}
|
||||
Jump();
|
||||
Move();
|
||||
RunSwitch();
|
||||
Animation();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
Jump();
|
||||
}
|
||||
|
||||
void RunSwitch()
|
||||
@ -47,22 +51,41 @@ public class PlayerManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
void Animation()
|
||||
{
|
||||
float localSpeed = 5f;
|
||||
if (Input.GetAxis("Horizontal") > 0)
|
||||
{
|
||||
playerModel.transform.rotation = Quaternion.Lerp(
|
||||
playerModel.transform.rotation,
|
||||
Quaternion.Euler(playerModel.transform.eulerAngles.x, 0f, playerModel.transform.eulerAngles.z),
|
||||
localSpeed * Time.deltaTime
|
||||
);
|
||||
}
|
||||
else if (Input.GetAxis("Horizontal") < 0)
|
||||
{
|
||||
playerModel.transform.rotation = Quaternion.Lerp(
|
||||
playerModel.transform.rotation,
|
||||
Quaternion.Euler(playerModel.transform.eulerAngles.x, -180f, playerModel.transform.eulerAngles.z),
|
||||
localSpeed * Time.deltaTime
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void Move()
|
||||
{
|
||||
rigidBody.MovePosition(
|
||||
transform.position +
|
||||
(transform.right * (run ? runSpeed : speed) * Input.GetAxis("Horizontal") * Time.deltaTime) +
|
||||
jumpPower
|
||||
(transform.right * (run ? runSpeed : speed) * Input.GetAxis("Horizontal") * Time.deltaTime)
|
||||
);
|
||||
}
|
||||
|
||||
void Jump()
|
||||
{
|
||||
Debug.Log(rigidBody.velocity.y);
|
||||
if (Input.GetAxisRaw("Jump") > 0) {
|
||||
if (rigidBody.velocity.y <= 2 && onGround)
|
||||
if (rigidBody.velocity.y <= 1 && onGround)
|
||||
{
|
||||
jumpPower = transform.up * jump * Time.deltaTime;
|
||||
rigidBody.AddForce(transform.up * jump * 10 * Time.deltaTime, ForceMode.VelocityChange);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -71,7 +94,7 @@ public class PlayerManager : MonoBehaviour
|
||||
{
|
||||
if (other.tag == "Ground" || other.tag == "Objects")
|
||||
{
|
||||
jumpPower = Vector3.zero;
|
||||
rigidBody.MovePosition(transform.position);
|
||||
onGround = true;
|
||||
}
|
||||
}
|
||||
@ -83,4 +106,16 @@ public class PlayerManager : MonoBehaviour
|
||||
onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnTriggerStay(Collider other)
|
||||
{
|
||||
if (other.tag == "Ground" || other.tag == "Objects")
|
||||
{
|
||||
if (rigidBody.velocity.y <= 1 && !onGround)
|
||||
{
|
||||
rigidBody.MovePosition(transform.position);
|
||||
onGround = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user