1
0
mirror of https://projects.caleb-brown.dev/UDRI-XRT/UDRIGEEKCup2024.git synced 2025-01-22 07:08:51 -05:00
UDRIGEEKCup2024/Assets/Scripts/OnTriggerForce.cs

35 lines
970 B
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityAtoms.BaseAtoms;
using UnityAtoms.Tags;
using UnityEngine;
namespace MAVRIC.GEEKCup
{
public class OnTriggerForce : MonoBehaviour
{
public float forceMultiplier = 1f;
public List<StringConstant> tagsMask = new ();
private void OnTriggerStay(Collider other)
{
if (!other.gameObject.HasAnyTag(tagsMask)) return;
var rb = other.attachedRigidbody;
if (rb == null) return;
// Calculate direction from object to transform
Vector3 direction = transform.position - rb.position;
// Normalize the direction to get a unit vector
direction.Normalize();
// Apply attractive force based on direction and attractForce
rb.AddForce(direction * forceMultiplier);
}
}
}