-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSway.cs
31 lines (23 loc) · 851 Bytes
/
Sway.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Sway : MonoBehaviour
{
public float amount = 0.08f;
public float maxAmount = 0.75f;
public float smoothAmount = 6f;
private Vector3 initialPosition;
void Start()
{
initialPosition = transform.localPosition;
}
void Update()
{
float movementX = -Input.GetAxis("Mouse X") * amount;
float movementY = -Input.GetAxis("Mouse Y") * amount;
movementX = Mathf.Clamp(movementX, -maxAmount, maxAmount);
movementY = Mathf.Clamp(movementY, -maxAmount, maxAmount);
Vector3 finalPosition = new Vector3(movementX, movementY, 0);
transform.localPosition = Vector3.Lerp(transform.localPosition, finalPosition + initialPosition, Time.deltaTime * smoothAmount);
}
}