Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class LegMover : MonoBehaviour
- {
- Vector3 euler;
- float curRot;
- bool isMoving = true;
- float moveSpeed = 0.4f;
- // Start is called before the first frame update
- void Start()
- {
- curRot = Random.Range(-1,2); // We start the leg at a random rotation, this makes it look like the legs are moving independently
- euler = transform.localRotation.eulerAngles; // We store the starting angle, we rotate around this later on
- }
- // Update is called once per frame
- void Update()
- {
- if(isMoving){
- curRot += moveSpeed; // We increase the current rotation
- transform.localRotation = Quaternion.Euler(euler.x,Mathf.Sin(curRot) * 20.0f,euler.z); // We apply the rotation to the joint
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement