Work on player movement
This commit is contained in:
parent
8aa168505d
commit
bab441e902
@ -332,6 +332,14 @@ PrefabInstance:
|
|||||||
m_Modification:
|
m_Modification:
|
||||||
m_TransformParent: {fileID: 327689121}
|
m_TransformParent: {fileID: 327689121}
|
||||||
m_Modifications:
|
m_Modifications:
|
||||||
|
- target: {fileID: 3339862426328537977, guid: 99c4e582c7358f346ab00dae4ae956f9, type: 3}
|
||||||
|
propertyPath: type
|
||||||
|
value: 4
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 3339862426328537977, guid: 99c4e582c7358f346ab00dae4ae956f9, type: 3}
|
||||||
|
propertyPath: speed
|
||||||
|
value: 500
|
||||||
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 8768991388683709944, guid: 99c4e582c7358f346ab00dae4ae956f9, type: 3}
|
- target: {fileID: 8768991388683709944, guid: 99c4e582c7358f346ab00dae4ae956f9, type: 3}
|
||||||
propertyPath: m_RootOrder
|
propertyPath: m_RootOrder
|
||||||
value: 7
|
value: 7
|
||||||
@ -389,6 +397,10 @@ PrefabInstance:
|
|||||||
m_Modification:
|
m_Modification:
|
||||||
m_TransformParent: {fileID: 327689121}
|
m_TransformParent: {fileID: 327689121}
|
||||||
m_Modifications:
|
m_Modifications:
|
||||||
|
- target: {fileID: 3339862426328537977, guid: 99c4e582c7358f346ab00dae4ae956f9, type: 3}
|
||||||
|
propertyPath: type
|
||||||
|
value: 4
|
||||||
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 8768991388683709944, guid: 99c4e582c7358f346ab00dae4ae956f9, type: 3}
|
- target: {fileID: 8768991388683709944, guid: 99c4e582c7358f346ab00dae4ae956f9, type: 3}
|
||||||
propertyPath: m_RootOrder
|
propertyPath: m_RootOrder
|
||||||
value: 6
|
value: 6
|
||||||
|
@ -4,7 +4,7 @@ using UnityEngine;
|
|||||||
|
|
||||||
public class PlatformManager : MonoBehaviour
|
public class PlatformManager : MonoBehaviour
|
||||||
{
|
{
|
||||||
public enum PlatformType {Pull, Push, RotateZ, RotateY, Speed};
|
public enum PlatformType {Pull, Push, RotateZ, RotateY, SpeedUp, SpeedDown};
|
||||||
public PlatformType type = PlatformType.Pull;
|
public PlatformType type = PlatformType.Pull;
|
||||||
public float speed = 5;
|
public float speed = 5;
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ public class PlayerController : MonoBehaviour
|
|||||||
float moveDirectionY;
|
float moveDirectionY;
|
||||||
public Vector3 jump;
|
public Vector3 jump;
|
||||||
public float jumpForce = 2.0f;
|
public float jumpForce = 2.0f;
|
||||||
private bool isGoundet = false;
|
private bool isGrounded = false;
|
||||||
public bool isRunning = false;
|
public bool isRunning = false;
|
||||||
|
|
||||||
private Vector3 follow = Vector3.zero;
|
private Vector3 follow = Vector3.zero;
|
||||||
@ -57,19 +57,47 @@ public class PlayerController : MonoBehaviour
|
|||||||
runningParticles.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
|
runningParticles.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input.GetKeyDown(KeyCode.Space) && isGoundet)
|
if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
|
||||||
{
|
{
|
||||||
Debug.Log("Jump");
|
Debug.Log("Jump");
|
||||||
rb.AddForce(transform.up * jumpSpeed * 500 * Time.deltaTime, ForceMode.Impulse);
|
rb.AddForce(transform.up * jumpSpeed * 500 * Time.deltaTime, ForceMode.Impulse);
|
||||||
isGoundet = false;
|
isGrounded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
rb.MovePosition(rb.position + moveDirection);
|
rb.MovePosition(rb.position + moveDirection);
|
||||||
}
|
}
|
||||||
|
void OnCollisionExit(Collision other)
|
||||||
void OnCollisionStay(Collision other)
|
|
||||||
{
|
{
|
||||||
isGoundet = true;
|
if (other.gameObject.tag == "platform")
|
||||||
|
{
|
||||||
|
Physics.gravity = -Vector3.up * 9.81f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnCollisionStay(Collision other){
|
||||||
|
if (other.gameObject.tag != "platform") return;
|
||||||
|
PlatformManager platform = other.gameObject.GetComponent<PlatformManager>();
|
||||||
|
if (platform == null)
|
||||||
|
{
|
||||||
|
// FIXME: Should platforms be allowed to not to have a PlatformManager?
|
||||||
|
// Debug.Log("ERROR");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector3 axis;
|
||||||
|
float angle;
|
||||||
|
axis = Vector3.Cross(-transform.up, -other.GetContact(0).normal);
|
||||||
|
if (platform.type == PlatformManager.PlatformType.SpeedUp)
|
||||||
|
{
|
||||||
|
angle = Mathf.Atan2(Vector3.Magnitude(axis), Vector3.Dot(-transform.up, -other.GetContact(0).normal));
|
||||||
|
transform.RotateAround(axis, angle);
|
||||||
|
// TODO: Rotate gravity to the center of platform
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnCollisionEnter(Collision other)
|
||||||
|
{
|
||||||
|
isGrounded = true;
|
||||||
if (other.gameObject.tag == "platform")
|
if (other.gameObject.tag == "platform")
|
||||||
{
|
{
|
||||||
Vector3 axis;
|
Vector3 axis;
|
||||||
@ -84,30 +112,35 @@ public class PlayerController : MonoBehaviour
|
|||||||
|
|
||||||
Vector3 gDirection;
|
Vector3 gDirection;
|
||||||
PlatformManager platform = other.gameObject.GetComponent<PlatformManager>();
|
PlatformManager platform = other.gameObject.GetComponent<PlatformManager>();
|
||||||
|
gDirection = -transform.up;
|
||||||
if (platform != null && platform.type == PlatformManager.PlatformType.Pull)
|
if (platform == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (platform.type == PlatformManager.PlatformType.Pull)
|
||||||
{
|
{
|
||||||
gDirection = -transform.up;
|
gDirection = -transform.up;
|
||||||
}
|
}
|
||||||
else if (platform != null && platform.type == PlatformManager.PlatformType.Push)
|
else if (platform.type == PlatformManager.PlatformType.Push)
|
||||||
{
|
{
|
||||||
gDirection = transform.up;
|
gDirection = transform.up;
|
||||||
}
|
}
|
||||||
else if (platform != null && (platform.type == PlatformManager.PlatformType.RotateY || platform.type == PlatformManager.PlatformType.RotateZ))
|
else if ((platform.type == PlatformManager.PlatformType.RotateY || platform.type == PlatformManager.PlatformType.RotateZ))
|
||||||
{
|
{
|
||||||
gDirection = -transform.up;
|
gDirection = -transform.up;
|
||||||
}
|
}
|
||||||
else if (platform != null && platform.type == PlatformManager.PlatformType.Speed)
|
else if (platform.type == PlatformManager.PlatformType.SpeedUp)
|
||||||
|
{
|
||||||
|
rb.AddForce(other.transform.forward * platform.speed * Time.deltaTime, ForceMode.Impulse);
|
||||||
|
gDirection = -transform.up;
|
||||||
|
}
|
||||||
|
else if (platform.type == PlatformManager.PlatformType.SpeedDown)
|
||||||
{
|
{
|
||||||
rb.AddForce(other.transform.forward * platform.speed * 10 * Time.deltaTime, ForceMode.Impulse);
|
rb.AddForce(other.transform.forward * platform.speed * 10 * Time.deltaTime, ForceMode.Impulse);
|
||||||
gDirection = -transform.up;
|
gDirection = -transform.up;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
gDirection = -transform.up;
|
|
||||||
}
|
|
||||||
|
|
||||||
Physics.gravity = gDirection * 9.81f;
|
Physics.gravity = gDirection * 9.81f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user