You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
982 B

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class RemotePlayer : Player {
  5. public Animator Animator;
  6. public GameObject PlayerModel;
  7. private float walkSpeed;
  8. private Vector3 lastPosition;
  9. private float LastSpeed = 0;
  10. public void Start()
  11. {
  12. lastPosition = transform.position;
  13. }
  14. protected override void Update()
  15. {
  16. DoAnimation();
  17. base.Update();
  18. }
  19. private void DoAnimation()
  20. {
  21. Vector3 dir = transform.position - lastPosition;
  22. lastPosition = transform.position;
  23. float DesiredSpeed = dir.magnitude * 10;
  24. float setSpeed = Mathf.Lerp(LastSpeed, DesiredSpeed, 0.1f);
  25. Animator.SetFloat("WalkSpeed", setSpeed);
  26. Debug.Log(setSpeed);
  27. LastSpeed = setSpeed;
  28. PlayerModel.transform.LookAt(PlayerModel.transform.position + dir, Vector3.up);
  29. //PlayerModel.transform.forward = dir.normalized;
  30. }
  31. }