-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSinWaveMove.cs
More file actions
50 lines (43 loc) · 1.48 KB
/
Copy pathSinWaveMove.cs
File metadata and controls
50 lines (43 loc) · 1.48 KB
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
46
47
48
49
50
// SinWaveMove.cs
// Last edited 9:42 PM 04/21/2015 by Aaron Freedman
using UnityEngine;
namespace Assets.PrototypingKit
{
public class SinWaveMove : MonoBehaviour
{
public enum MoveDirection
{
x,
y,
z
};
public MoveDirection moveDirection;
public float moveAmount;
public float moveSpeed;
public float lerpSpeed;
private Vector3 originalPos;
private void Start()
{
originalPos = transform.position;
}
private void Update()
{
Vector3 targetPosition = Vector3.zero;
switch (moveDirection)
{
case MoveDirection.x:
targetPosition = new Vector3((Mathf.Sin(Time.time * moveSpeed) * moveAmount) + originalPos.x, originalPos.y, originalPos.z);
break;
case MoveDirection.y:
targetPosition = new Vector3(originalPos.x, (Mathf.Sin(Time.time * moveSpeed) * moveAmount) + originalPos.y, originalPos.z);
break;
case MoveDirection.z:
targetPosition = new Vector3(originalPos.x, originalPos.y, (Mathf.Sin(Time.time * moveSpeed) * moveAmount) + originalPos.z);
break;
default:
break;
}
transform.position = Vector3.Lerp(transform.position, targetPosition, lerpSpeed * Time.deltaTime);
}
}
}