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
|
||||
{
|
||||
|
||||
@@ -17,8 +17,19 @@ namespace ArcadeVP
|
||||
public InputAction steeringAction;
|
||||
public InputAction accelerationAction;
|
||||
public InputAction brakeAction;
|
||||
public InputAction lookAction;
|
||||
public InputAction lookBehindAction;
|
||||
#endif
|
||||
|
||||
[Header("Camera Control")]
|
||||
[Tooltip("The parent object of the camera that will rotate when you look around.")]
|
||||
public Transform cameraPivot;
|
||||
public float lookSensitivity = 15f;
|
||||
public float lookReturnSpeed = 5f;
|
||||
|
||||
private float currentPan = 0f;
|
||||
private float currentTilt = 0f;
|
||||
|
||||
[Header("Input Smoothing")]
|
||||
public bool useSmoothing = true;
|
||||
public float steeringLerpSpeed = 10f;
|
||||
@@ -35,6 +46,8 @@ namespace ArcadeVP
|
||||
steeringAction?.Enable();
|
||||
accelerationAction?.Enable();
|
||||
brakeAction?.Enable();
|
||||
lookAction?.Enable();
|
||||
lookBehindAction?.Enable();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -44,11 +57,23 @@ namespace ArcadeVP
|
||||
steeringAction?.Disable();
|
||||
accelerationAction?.Disable();
|
||||
brakeAction?.Disable();
|
||||
lookAction?.Disable();
|
||||
lookBehindAction?.Disable();
|
||||
#endif
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Pause controls during UI sequences
|
||||
if (GameManager.Instance != null && !GameManager.Instance.isGameActive)
|
||||
{
|
||||
if (arcadeVehicleController != null)
|
||||
{
|
||||
arcadeVehicleController.ProvideInputs(0f, 0f, 1f); // Slam the brakes
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
float targetSteering = 0f;
|
||||
float targetAcceleration = 0f;
|
||||
float targetBrake = 0f;
|
||||
@@ -85,6 +110,55 @@ namespace ArcadeVP
|
||||
{
|
||||
arcadeVehicleController.ProvideInputs(currentSteering, currentAcceleration, currentBrake);
|
||||
}
|
||||
|
||||
HandleCameraLook();
|
||||
}
|
||||
|
||||
private void HandleCameraLook()
|
||||
{
|
||||
if (cameraPivot == null) return;
|
||||
|
||||
Vector2 lookInput = Vector2.zero;
|
||||
bool lookBehind = false;
|
||||
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
if (lookAction != null) lookInput = lookAction.ReadValue<Vector2>();
|
||||
if (lookBehindAction != null) lookBehind = lookBehindAction.IsPressed();
|
||||
#else
|
||||
lookInput = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
|
||||
lookBehind = Input.GetKey(KeyCode.C);
|
||||
#endif
|
||||
|
||||
if (lookBehind)
|
||||
{
|
||||
// Snap the Cinemachine targets directly to the front (which puts the camera behind looking forward, or vice versa depending on setup,
|
||||
// but rotating 180 degrees perfectly reverses the Follow and LookAt positions!)
|
||||
cameraPivot.localRotation = Quaternion.Euler(0, 180f, 0);
|
||||
currentPan = 180f;
|
||||
currentTilt = 0f;
|
||||
}
|
||||
else if (lookInput.sqrMagnitude > 0.01f)
|
||||
{
|
||||
// Orbit the Cinemachine targets around the car
|
||||
currentPan += lookInput.x * lookSensitivity * Time.deltaTime;
|
||||
currentTilt -= lookInput.y * lookSensitivity * Time.deltaTime;
|
||||
|
||||
// Clamp the vertical tilt so it doesn't go under the floor or over the roof wildly
|
||||
currentTilt = Mathf.Clamp(currentTilt, -20f, 45f);
|
||||
|
||||
// Clamp the horizontal pan so they can only look up to 90 degrees left or right
|
||||
// (Looking behind must be done via the button)
|
||||
currentPan = Mathf.Clamp(currentPan, -90f, 90f);
|
||||
|
||||
cameraPivot.localRotation = Quaternion.Euler(currentTilt, currentPan, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Auto-center the Cinemachine targets back to the default driving view
|
||||
currentPan = Mathf.LerpAngle(currentPan, 0f, Time.deltaTime * lookReturnSpeed);
|
||||
currentTilt = Mathf.LerpAngle(currentTilt, 0f, Time.deltaTime * lookReturnSpeed);
|
||||
cameraPivot.localRotation = Quaternion.Euler(currentTilt, currentPan, 0);
|
||||
}
|
||||
}
|
||||
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
@@ -115,6 +189,15 @@ namespace ArcadeVP
|
||||
.WithGroup("Keyboard");
|
||||
brakeAction.AddBinding("<Gamepad>/buttonSouth")
|
||||
.WithGroup("Gamepad");
|
||||
|
||||
lookAction = new InputAction("Look", InputActionType.Value);
|
||||
lookAction.expectedControlType = "Vector2";
|
||||
lookAction.AddBinding("<Pointer>/delta");
|
||||
lookAction.AddBinding("<Gamepad>/rightStick");
|
||||
|
||||
lookBehindAction = new InputAction("LookBehind", InputActionType.Button);
|
||||
lookBehindAction.AddBinding("<Keyboard>/c");
|
||||
lookBehindAction.AddBinding("<Gamepad>/rightStickPress");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user