blob: 81a70054d00db1539da62d988474429c47ebc7b5 (
plain)
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
38
39
40
41
42
43
44
45
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GravityPlane : GravitySource
{
[SerializeField]
float gravity = 9.81f;
[SerializeField]
float range = 1f;
public override Vector3 GetGravity(Vector3 position)
{
Vector3 up = transform.up;
float distance = Vector3.Dot(up, position - transform.position);
if(distance > range)
return Vector3.zero;
float g = -gravity;
if (distance > 0f)
g *= 1f - distance / range;
return -gravity * up;
}
void OnDrawGizmos()
{
Vector3 scale = transform.localScale;
scale.y = range;
Gizmos.matrix = Matrix4x4.TRS(
transform.position,
transform.rotation,
scale
);
//transform.localToWorldMatrix;
Vector3 size = new Vector3(1f, 0f, 1f);
Gizmos.color = Color.yellow;
Gizmos.DrawWireCube(Vector3.zero, size);
if (range > 0f)
{
Gizmos.color = Color.cyan;
Gizmos.DrawWireCube(Vector3.up, size);
}
}
}
|