Advertisement
Guest User

James Q Assignment Animation

a guest
Mar 20th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class LegMover : MonoBehaviour
  6. {
  7.     Vector3 euler;
  8.     float curRot;
  9.     bool isMoving = true;
  10.     float moveSpeed = 0.4f;
  11.  
  12.     // Start is called before the first frame update
  13.     void Start()
  14.     {
  15.         curRot = Random.Range(-1,2); // We start the leg at a random rotation, this makes it look like the legs are moving independently
  16.         euler = transform.localRotation.eulerAngles; // We store the starting angle, we rotate around this later on
  17.     }
  18.  
  19.     // Update is called once per frame
  20.     void Update()
  21.     {
  22.         if(isMoving){
  23.             curRot += moveSpeed; // We increase the current rotation
  24.  
  25.             transform.localRotation = Quaternion.Euler(euler.x,Mathf.Sin(curRot) * 20.0f,euler.z); // We apply the rotation to the joint
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement