MiniGames/Assets/Scripts/SkyWalker/Skywalker_BounceObstacle.cs

38 lines
1.4 KiB
C#
Raw Normal View History

2025-09-01 00:01:33 +05:00
using UnityEngine;
[RequireComponent(typeof(MeshCollider))]
public class Skywalker_BounceObstacle : MonoBehaviour
{
[Header("Bounce Settings")]
public float bounceForce = 15f; // how strong the bounce is
public bool resetYVelocity = true; // reset vertical velocity before bounce
2025-09-06 23:30:06 +05:00
Skywalker_PlayerController playerController;
2025-09-01 00:01:33 +05:00
private void Reset()
{
Collider col = GetComponent<Collider>();
if (col != null)
col.isTrigger = false; // solid collider by default
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Player"))
{
2025-09-06 23:30:06 +05:00
if(playerController == null) {playerController=collision.gameObject.GetComponent<Skywalker_PlayerController>();};
2025-09-01 00:01:33 +05:00
Rigidbody rb = collision.gameObject.GetComponent<Rigidbody>();
if (rb != null)
{
// Optionally reset Y velocity so bounce is consistent
if (resetYVelocity)
rb.velocity = new Vector3(rb.velocity.x, 0f, rb.velocity.z);
// Apply bounce force
rb.AddForce(Vector3.up * bounceForce, ForceMode.VelocityChange);
2025-09-06 23:30:06 +05:00
//playerController.animator.SetBool("IsGrounded", false);
playerController.animator.SetTrigger("Jump");
2025-09-01 00:01:33 +05:00
Debug.Log("Player bounced!");
}
}
}
}