|
@ -7,6 +7,10 @@ public class BoatController : BuoyantObject { |
|
|
|
|
|
|
|
|
public float trunSpeed = 0.5f; |
|
|
public float trunSpeed = 0.5f; |
|
|
public float breakSpeed = 20f; |
|
|
public float breakSpeed = 20f; |
|
|
|
|
|
[Range(0.8f,1)] |
|
|
|
|
|
public float stopRatio = 0.95f; |
|
|
|
|
|
|
|
|
|
|
|
private bool applyBreak = true; |
|
|
|
|
|
|
|
|
// Use this for initialization
|
|
|
// Use this for initialization
|
|
|
void Start() { |
|
|
void Start() { |
|
@ -17,6 +21,10 @@ public class BoatController : BuoyantObject { |
|
|
lookAtDir(Vector3.ProjectOnPlane(rb.velocity, Vector3.up)); |
|
|
lookAtDir(Vector3.ProjectOnPlane(rb.velocity, Vector3.up)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void FixedUpdate() { |
|
|
|
|
|
|
|
|
|
|
|
doBreak(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
// Update is called once per frame
|
|
|
void lookAtDir(Vector3 inputDir) { |
|
|
void lookAtDir(Vector3 inputDir) { |
|
@ -38,4 +46,42 @@ public class BoatController : BuoyantObject { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void doBreak() { |
|
|
|
|
|
if (!applyBreak) |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
Vector3 vel = rb.velocity; |
|
|
|
|
|
Vector3 flatVel = Vector3.ProjectOnPlane(vel, Vector3.up); |
|
|
|
|
|
|
|
|
|
|
|
flatVel *= stopRatio; |
|
|
|
|
|
flatVel.y = vel.y; |
|
|
|
|
|
rb.velocity = flatVel; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public override IEnumerator pushObject(Vector3 point, float power, float totalTime) { |
|
|
|
|
|
Vector3 dir = transform.position - point; |
|
|
|
|
|
dir = Vector3.ProjectOnPlane(dir, Vector3.up); |
|
|
|
|
|
dir.Normalize(); |
|
|
|
|
|
|
|
|
|
|
|
float elapsedTime = 0; |
|
|
|
|
|
|
|
|
|
|
|
Vector3 force = dir * power; |
|
|
|
|
|
rb.AddForce(force,ForceMode.Impulse); |
|
|
|
|
|
|
|
|
|
|
|
while (elapsedTime < totalTime) { |
|
|
|
|
|
applyBreak = false; |
|
|
|
|
|
|
|
|
|
|
|
force = dir * power * Time.deltaTime; |
|
|
|
|
|
rb.AddForce(force); |
|
|
|
|
|
|
|
|
|
|
|
yield return new WaitForEndOfFrame(); |
|
|
|
|
|
|
|
|
|
|
|
elapsedTime += Time.deltaTime; |
|
|
|
|
|
} |
|
|
|
|
|
applyBreak = true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |