65 lines
2.2 KiB
C#
65 lines
2.2 KiB
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class ArmSwingLocomotion : MonoBehaviour
|
||
|
{
|
||
|
public GameObject LeftHand;
|
||
|
public GameObject RightHand;
|
||
|
public GameObject CenterEyeCamera;
|
||
|
public GameObject ForwardDirection;
|
||
|
|
||
|
private Vector3 PositionPreviousFrameLeftHand;
|
||
|
private Vector3 PositionPreviousFrameRightHand;
|
||
|
private Vector3 PlayerPositionPreviousFrame;
|
||
|
private Vector3 PlayerPositionCurrentFrame;
|
||
|
private Vector3 PositionCurrentFrameLeftHand;
|
||
|
private Vector3 PositionCurrentFrameRightHand;
|
||
|
|
||
|
public float Speed;
|
||
|
private float HandSpeed;
|
||
|
|
||
|
// Start is called before the first frame update
|
||
|
void Start()
|
||
|
{
|
||
|
PlayerPositionPreviousFrame = transform.position;
|
||
|
PositionPreviousFrameLeftHand = LeftHand.transform.position;
|
||
|
PlayerPositionPreviousFrame = RightHand.transform.position;
|
||
|
}
|
||
|
|
||
|
// Update is called once per frame
|
||
|
void Update()
|
||
|
{
|
||
|
|
||
|
|
||
|
|
||
|
float Yrot = CenterEyeCamera.transform.eulerAngles.y;
|
||
|
ForwardDirection.transform.eulerAngles = new Vector3(0, Yrot, 0);
|
||
|
|
||
|
PositionCurrentFrameLeftHand = LeftHand.transform.position;
|
||
|
PositionCurrentFrameRightHand = RightHand.transform.position;
|
||
|
|
||
|
PlayerPositionCurrentFrame = transform.position;
|
||
|
|
||
|
//Debug.Log("Previous" + PositionPreviousFrameLeftHand);
|
||
|
//Debug.Log("Current" + PositionCurrentFrameLeftHand);
|
||
|
|
||
|
var playerDistanceMoved = Vector3.Distance(PlayerPositionCurrentFrame, PlayerPositionPreviousFrame);
|
||
|
var leftHandDistanceMoved = Vector3.Distance(PositionCurrentFrameLeftHand, PositionPreviousFrameLeftHand);
|
||
|
var rightHandDistanceMoved = Vector3.Distance(PositionCurrentFrameRightHand, PositionPreviousFrameRightHand);
|
||
|
|
||
|
HandSpeed = ((leftHandDistanceMoved - playerDistanceMoved) + (rightHandDistanceMoved - playerDistanceMoved));
|
||
|
|
||
|
if (Time.timeSinceLevelLoad > 1f)
|
||
|
{
|
||
|
transform.position += ForwardDirection.transform.forward * HandSpeed * Speed * Time.deltaTime;
|
||
|
}
|
||
|
|
||
|
PositionPreviousFrameLeftHand = PositionCurrentFrameLeftHand;
|
||
|
PositionPreviousFrameRightHand = PositionCurrentFrameRightHand;
|
||
|
|
||
|
PlayerPositionPreviousFrame = PlayerPositionCurrentFrame;
|
||
|
|
||
|
}
|
||
|
}
|