Visual, Gliding, Jumping

actions are now visualized, Gliding, fixed jumping
This commit is contained in:
Richard Ott
2018-09-01 12:29:01 +02:00
parent 6206070b27
commit 9a4962464d
4 changed files with 107 additions and 19 deletions

8
Assets/Prefabs.meta Normal file
View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9742d4800b8a66b4d9ec800f36840aff
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -265,9 +265,13 @@ MonoBehaviour:
lockMouse: 1
speed: 0.5
theLurch: {fileID: 4675101163920296}
lurchMaterial: {fileID: 0}
maxJumpForce: 10
forceIncreaseSpeed: 0.5
normalColor: {r: 0.14509805, g: 0.4784314, b: 1, a: 0}
fullyChargedColor: {r: 1, g: 0.6223973, b: 0, a: 0}
fullyChargedColor: {r: 0.95649004, g: 0, b: 1, a: 0}
normalSize: {x: 0, y: 0, z: 0}
chargedSizeModifier: 0.5
canStick: 1
cooldown: 0
canGlide: 1
glideForce: 3

View File

@@ -477,6 +477,16 @@ Prefab:
propertyPath: m_RootOrder
value: 5
objectReference: {fileID: 0}
- target: {fileID: 114123996009525022, guid: 8bcf2afca6664234f83b5ee8381b1975,
type: 2}
propertyPath: canGlide
value: 1
objectReference: {fileID: 0}
- target: {fileID: 114123996009525022, guid: 8bcf2afca6664234f83b5ee8381b1975,
type: 2}
propertyPath: glideForce
value: 3
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 8bcf2afca6664234f83b5ee8381b1975, type: 2}
m_IsPrefabAsset: 0

View File

@@ -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,34 @@ 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 +149,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;
}
}
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)
{
Debug.DrawRay(theLurch.position, Vector3.forward* 1.6f);
if (Physics.Raycast(theLurch.position, Vector3.forward, out hit, 1.6f))
if (AmSticking())
{
return true;
}
return false;
}
bool AmSticking()
{
RaycastHit hit;
if (Physics.Raycast(theLurch.position, theLurch.forward, out hit, 1.4f))
{
return true;
}
if (lurchBody.isKinematic)
{
return true;
}
return false;