Advertisement
Hygcgggnngff

Yeet Hammer by Antoca

Aug 4th, 2024
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class YeetHammerScript : MonoBehaviour
  4. {
  5.     // Force to apply when the hammer hits an object
  6.     public float yeetForce = 1000f;
  7.  
  8.     // Direction to apply the force (relative to the hammer)
  9.     public Vector3 yeetDirection = new Vector3(0, 1, 1);
  10.  
  11.     void OnCollisionEnter(Collision collision)
  12.     {
  13.         // Check if the object has a Rigidbody
  14.         Rigidbody rb = collision.collider.GetComponent<Rigidbody>();
  15.  
  16.         if (rb != null)
  17.         {
  18.             // Calculate the direction based on the hammer's orientation
  19.             Vector3 forceDirection = transform.TransformDirection(yeetDirection.normalized);
  20.  
  21.             // Apply the force to "yeet" the object
  22.             rb.AddForce(forceDirection * yeetForce, ForceMode.Impulse);
  23.         }
  24.     }
  25. }
  26.  
Tags: Script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement