Merge branch 'master' into respawn
This commit is contained in:
@@ -21,35 +21,55 @@ public class LurchMovement : MonoBehaviour {
|
||||
[Header("Lurch")]
|
||||
public Transform theLurch;
|
||||
private Rigidbody lurchBody;
|
||||
public Material lurchMaterial;
|
||||
|
||||
[Header("Jump Charge")]
|
||||
public float maxJumpForce;
|
||||
private float currentJumpForce;
|
||||
public float forceIncreaseSpeed;
|
||||
|
||||
public Color normalColor;
|
||||
public Color fullyChargedColor;
|
||||
private Color lerpedColor;
|
||||
|
||||
public Vector3 normalSize;
|
||||
[Range(0.1f, 1.0f)]
|
||||
public float chargedSizeModifier;
|
||||
private Vector3 chargedSize;
|
||||
private Vector3 currentSize;
|
||||
|
||||
static float t = 0.0f;
|
||||
|
||||
[Header("Jump n Stick")]
|
||||
public bool canStick;
|
||||
[SerializeField]
|
||||
private float cooldown;
|
||||
|
||||
[Header("Gliding")]
|
||||
public bool canGlide;
|
||||
private Vector3 glideSize;
|
||||
[Range(1.0f, 10.0f)]
|
||||
public float glideForce;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
lurchBody = theLurch.GetComponent<Rigidbody>();
|
||||
normalSize = theLurch.transform.localScale;
|
||||
chargedSize = theLurch.transform.localScale * chargedSizeModifier;
|
||||
glideSize = new Vector3(normalSize.x, normalSize.y * 0.5f, normalSize.z);
|
||||
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
theLurch.rotation = Quaternion.Euler(0, transform.eulerAngles.y, 0);
|
||||
|
||||
theLurch.GetComponent<Renderer>().material.color = lerpedColor;
|
||||
theLurch.transform.localScale = currentSize;
|
||||
|
||||
MouseControl();
|
||||
JumpControl();
|
||||
SmoothFollow();
|
||||
|
||||
|
||||
Debug.DrawRay(theLurch.position, Vector3.down * 0.45f, Color.blue);
|
||||
|
||||
Gliding();
|
||||
}
|
||||
|
||||
void MouseControl()
|
||||
@@ -94,15 +114,33 @@ public class LurchMovement : MonoBehaviour {
|
||||
if (Input.GetButton("Fire1") && currentJumpForce < maxJumpForce)
|
||||
{
|
||||
currentJumpForce += forceIncreaseSpeed;
|
||||
lerpedColor = Color.Lerp(normalColor, fullyChargedColor, t);
|
||||
if (t < 1.0f)
|
||||
{
|
||||
t += 2 * Time.deltaTime;
|
||||
}
|
||||
|
||||
currentSize = Vector3.Lerp(currentSize, chargedSize, Time.deltaTime * 1.5f);
|
||||
|
||||
}
|
||||
else if(!Input.GetButton("Fire1"))
|
||||
{
|
||||
lerpedColor = normalColor;
|
||||
t = 0.0f;
|
||||
currentSize = normalSize;
|
||||
|
||||
}
|
||||
|
||||
if (cooldown > 0.0f)
|
||||
{
|
||||
cooldown -= Time.deltaTime;
|
||||
currentJumpForce = 0.0f;
|
||||
}
|
||||
|
||||
if (Input.GetButtonUp("Fire1")) {
|
||||
cooldown += 0.5f;
|
||||
cooldown = 0.5f;
|
||||
lurchBody.isKinematic = false;
|
||||
Debug.Log("Ich springe");
|
||||
|
||||
lurchBody.AddForce(theLurch.forward * currentJumpForce, ForceMode.Impulse);
|
||||
lurchBody.AddForce(theLurch.up * currentJumpForce, ForceMode.Impulse);
|
||||
}
|
||||
@@ -110,31 +148,58 @@ public class LurchMovement : MonoBehaviour {
|
||||
{
|
||||
lurchBody.isKinematic = true;
|
||||
}
|
||||
|
||||
if (!LurchOnGround())
|
||||
else if (!LurchOnGround() && Time.time > cooldown && !AmSticking())
|
||||
{
|
||||
currentJumpForce = 0.0f;
|
||||
lurchBody.isKinematic = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Gliding()
|
||||
{
|
||||
|
||||
if (canGlide && !lurchBody.isKinematic && Input.GetButton("Fire1") &&!LurchOnGround())
|
||||
{
|
||||
Debug.Log("Ich kann jetzt gleiten");
|
||||
theLurch.transform.localScale = glideSize;
|
||||
|
||||
lurchBody.AddForce(theLurch.forward * glideForce);
|
||||
lurchBody.AddForce(theLurch.up * 0.08f, ForceMode.Impulse);
|
||||
|
||||
}
|
||||
if (!Input.GetButton("Fire1"))
|
||||
{
|
||||
theLurch.transform.localScale = currentSize;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public bool LurchOnGround()
|
||||
{
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(theLurch.position, Vector3.down, out hit, 0.4f))
|
||||
if (Physics.Raycast(theLurch.position, Vector3.down, out hit, 0.36f) && cooldown <= 0.0f)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (canStick)
|
||||
if (AmSticking())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Debug.DrawRay(theLurch.position, Vector3.forward* 1.6f);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Physics.Raycast(theLurch.position, Vector3.forward, out hit, 1.6f))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool AmSticking()
|
||||
{
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(theLurch.position, theLurch.forward, out hit, 1.4f))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (lurchBody.isKinematic)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user