-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThruster.cs
37 lines (32 loc) · 1.06 KB
/
Thruster.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Thruster : MonoBehaviour
{
public float thrustersForce = 10;
public float maxDistance = 3f;
public Rigidbody rb;
public Transform[] thrusters;
Vector3 downForce;
void FixedUpdate()
{
RaycastHit hit;
foreach (Transform thruster in thrusters)
{
Vector3 downForce;
float distancePercentage;
if (Physics.Raycast(thruster.position, thruster.up*-1, out hit, maxDistance))
{
distancePercentage = 1 - (hit.distance / maxDistance);
downForce = transform.up * thrustersForce * Time.deltaTime * rb.mass * distancePercentage;
rb.AddForceAtPosition(downForce, thruster.position);
Debug.DrawRay(thruster.position, thruster.up * -1 * maxDistance, Color.green);
rb.drag = 2f;
}
else
{
rb.drag = 0.5f;
}
}
}
}