1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Events;
- using KairoEngine.Core;
- namespace KairoEngine.CharacterSystem
- {
- /// <summary>
- /// Action to turn a character towards a point.
- /// </summary>
- public class CharacterTurnToPointAction : IAction
- {
- CharacterController character; // Reference to the character that will move
- Vector3 point; // Where to turn
- // Constructor
- public CharacterTurnToPointAction(CharacterController character, Vector3 point)
- {
- this.character = character;
- this.point = point;
- this.point.y = 0f;
- }
- public void Start()
- {
- Quaternion targetRotation = Quaternion.LookRotation (point - character.transform.position);
- character.animator.transform.rotation = Quaternion.Slerp (character.animator.transform.rotation, targetRotation, 100f * Time.deltaTime);
- }
- public void Update()
- {
- Quaternion targetRotation = Quaternion.LookRotation (point - character.transform.position);
- character.animator.transform.rotation = Quaternion.Slerp (character.animator.transform.rotation, targetRotation, 100f * Time.deltaTime);
- }
- public void End() { }
- public bool IsDone()
- {
- return true;
- }
- }
- }
|