Building out Golf Level and mission states and improved AI
This commit is contained in:
@@ -185,7 +185,7 @@ namespace ArcadeVP
|
||||
|
||||
rb.AddForce(-transform.up * downforce * rb.mass);
|
||||
|
||||
carBody.MoveRotation(Quaternion.Slerp(carBody.rotation, Quaternion.FromToRotation(carBody.transform.up, hit.normal) * carBody.transform.rotation, 0.12f));
|
||||
carBody.MoveRotation(Quaternion.Slerp(carBody.rotation, Quaternion.FromToRotation(carBody.transform.up, hit.normal) * carBody.transform.rotation, 8f * Time.fixedDeltaTime));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -195,7 +195,8 @@ namespace ArcadeVP
|
||||
carBody.AddTorque(Vector3.up * steeringInput * turn * 100 * TurnMultiplyer);
|
||||
}
|
||||
|
||||
carBody.MoveRotation(Quaternion.Slerp(carBody.rotation, Quaternion.FromToRotation(carBody.transform.up, Vector3.up) * carBody.transform.rotation, 0.02f));
|
||||
// In the air, level out much slower so jumps look natural, not flat instantly
|
||||
carBody.MoveRotation(Quaternion.Slerp(carBody.rotation, Quaternion.FromToRotation(carBody.transform.up, Vector3.up) * carBody.transform.rotation, 1.5f * Time.fixedDeltaTime));
|
||||
rb.linearVelocity = Vector3.Lerp(rb.linearVelocity, rb.linearVelocity + Vector3.down * gravity, Time.deltaTime * gravity);
|
||||
}
|
||||
}
|
||||
@@ -240,17 +241,31 @@ namespace ArcadeVP
|
||||
|
||||
private void UpdateGroundedState()
|
||||
{
|
||||
origin = rb.position + radius * Vector3.up;
|
||||
// Cast from the car's local UP, not world UP
|
||||
origin = rb.position + radius * transform.up;
|
||||
Vector3 direction = -transform.up;
|
||||
float maxdistance = radius + 0.2f;
|
||||
|
||||
// Give it a bit more reach so it doesn't instantly think it's flying on bumps/slopes
|
||||
float maxdistance = radius + 0.8f;
|
||||
|
||||
if (groundCheck == GroundCheckType.RayCast)
|
||||
{
|
||||
isGrounded = Physics.Raycast(rb.position, Vector3.down, out hit, maxdistance, drivableSurface);
|
||||
// Cast locally downward so it stays stuck to walls/slopes
|
||||
isGrounded = Physics.Raycast(rb.position, direction, out hit, maxdistance, drivableSurface);
|
||||
|
||||
// Fallback: If local down fails (e.g. cresting a hill), check world down just in case
|
||||
if (!isGrounded)
|
||||
{
|
||||
isGrounded = Physics.Raycast(rb.position, Vector3.down, out hit, maxdistance, drivableSurface);
|
||||
}
|
||||
}
|
||||
else if (groundCheck == GroundCheckType.SphereCast)
|
||||
{
|
||||
isGrounded = Physics.SphereCast(origin, radius + 0.1f, direction, out hit, maxdistance, drivableSurface);
|
||||
isGrounded = Physics.SphereCast(origin, radius * 0.8f, direction, out hit, maxdistance, drivableSurface);
|
||||
if (!isGrounded)
|
||||
{
|
||||
isGrounded = Physics.SphereCast(origin, radius * 0.8f, Vector3.down, out hit, maxdistance, drivableSurface);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user