-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTractorBeam.cs
More file actions
24 lines (23 loc) · 806 Bytes
/
TractorBeam.cs
File metadata and controls
24 lines (23 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using UnityEngine;
using System.Collections;
public class TractorBeam : MonoBehaviour
{
public float tractorForce;
public float tractorLength;
public Transform target;
void OnTriggerenter (Collider other)
{
}
void OnTriggerStay (Collider other)
{
Vector3 force = ScriptUtilities.Vector3Utils.Subtract (target.position, other.transform.position);
float distance = Vector3.Distance (target.position, other.transform.position);
float fallOffMultiplier = distance / tractorLength;
Debug.DrawLine (target.position, other.transform.position, Color.blue);
other.attachedRigidbody.AddForce (force.normalized * (tractorForce / fallOffMultiplier));
}
void OnTriggerExit (Collider other)
{
Debug.DrawLine (target.position, other.transform.position, Color.red);
}
}