CharacterTurnToPointAction.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Events;
  5. using KairoEngine.Core;
  6. namespace KairoEngine.CharacterSystem
  7. {
  8. /// <summary>
  9. /// Action to turn a character towards a point.
  10. /// </summary>
  11. public class CharacterTurnToPointAction : IAction
  12. {
  13. CharacterController character; // Reference to the character that will move
  14. Vector3 point; // Where to turn
  15. // Constructor
  16. public CharacterTurnToPointAction(CharacterController character, Vector3 point)
  17. {
  18. this.character = character;
  19. this.point = point;
  20. this.point.y = 0f;
  21. }
  22. public void Start()
  23. {
  24. Quaternion targetRotation = Quaternion.LookRotation (point - character.transform.position);
  25. character.animator.transform.rotation = Quaternion.Slerp (character.animator.transform.rotation, targetRotation, 100f * Time.deltaTime);
  26. }
  27. public void Update()
  28. {
  29. Quaternion targetRotation = Quaternion.LookRotation (point - character.transform.position);
  30. character.animator.transform.rotation = Quaternion.Slerp (character.animator.transform.rotation, targetRotation, 100f * Time.deltaTime);
  31. }
  32. public void End() { }
  33. public bool IsDone()
  34. {
  35. return true;
  36. }
  37. }
  38. }