Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class YeetHammerScript : MonoBehaviour
- {
- // Force to apply when the hammer hits an object
- public float yeetForce = 1000f;
- // Direction to apply the force (relative to the hammer)
- public Vector3 yeetDirection = new Vector3(0, 1, 1);
- void OnCollisionEnter(Collision collision)
- {
- // Check if the object has a Rigidbody
- Rigidbody rb = collision.collider.GetComponent<Rigidbody>();
- if (rb != null)
- {
- // Calculate the direction based on the hammer's orientation
- Vector3 forceDirection = transform.TransformDirection(yeetDirection.normalized);
- // Apply the force to "yeet" the object
- rb.AddForce(forceDirection * yeetForce, ForceMode.Impulse);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement