add unlock system for tools
This commit is contained in:
@@ -20,7 +20,6 @@ private void Update()
|
||||
{
|
||||
if (GameManager.Instance.PlayerController != null)
|
||||
{
|
||||
SetGroundPlane();
|
||||
DrawTargetProjection();
|
||||
}
|
||||
}
|
||||
@@ -43,28 +42,51 @@ private void DrawTargetProjection()
|
||||
targetProjection = GetComponentInChildren<DecalProjector>();
|
||||
}
|
||||
|
||||
Transform player = GameManager.Instance.PlayerController.DougBody.transform;
|
||||
Transform camera = GameManager.Instance.PlayerController.cameraController.MainCamera.transform;
|
||||
|
||||
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
|
||||
if (handGroundPlane.Raycast(ray, out var distance))
|
||||
Vector3 targetPoint;
|
||||
|
||||
// First try real world geometry
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, 1000f))
|
||||
{
|
||||
Vector3 hitPoint = ray.GetPoint(distance);
|
||||
|
||||
float distanceFromPoint = Vector3.Distance(hitPoint, transform.position);
|
||||
if (distanceFromPoint > range)
|
||||
{
|
||||
Vector3 directionTowardMouse = (hitPoint - transform.position).normalized;
|
||||
targetProjection.transform.position = new Vector3(transform.position.x, hitPoint.y, transform.position.z);
|
||||
targetProjection.transform.position += directionTowardMouse * range;
|
||||
|
||||
throwForce = range;
|
||||
}
|
||||
else
|
||||
{
|
||||
targetProjection.gameObject.SetActive(true);
|
||||
targetProjection.transform.position = hitPoint;
|
||||
throwForce = distanceFromPoint;
|
||||
}
|
||||
targetPoint = hit.point;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback plane if nothing hit
|
||||
Plane plane = new Plane(Vector3.up, player.position);
|
||||
|
||||
if (!plane.Raycast(ray, out float distance))
|
||||
return;
|
||||
|
||||
targetPoint = ray.GetPoint(distance);
|
||||
}
|
||||
|
||||
// Flatten relative to player
|
||||
Vector3 offset = targetPoint - player.position;
|
||||
offset.y = 0f;
|
||||
|
||||
// Clamp range
|
||||
offset = Vector3.ClampMagnitude(offset, range);
|
||||
throwForce = offset.magnitude;
|
||||
|
||||
// Final position
|
||||
Vector3 finalPosition = player.position + offset;
|
||||
|
||||
// Snap back to ground
|
||||
if (Physics.Raycast(
|
||||
finalPosition + Vector3.up * 10f,
|
||||
Vector3.down,
|
||||
out RaycastHit groundHit,
|
||||
50f))
|
||||
{
|
||||
finalPosition = groundHit.point;
|
||||
}
|
||||
|
||||
targetProjection.transform.position = finalPosition;
|
||||
}
|
||||
|
||||
public override void Use()
|
||||
|
||||
Reference in New Issue
Block a user