Hi
I am writing a custom script to rotate the player at a speed. But the FSM works but how can i rest the Vector3 back to zero. On exit?
// (c) Copyright HutongGames, LLC 2010-2016. All rights reserved.
// Action made by NCMedia
// Rotate Player Over Time
// __ECO__ __PLAYMAKER__ __ACTION__
using UnityEngine;
using System.Collections;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Transform)]
[Tooltip("This will transform rotate an object over a set time")]
public class RotateOverTime : FsmStateAction {
[RequiredField]
[Tooltip("Game Object to move")]
public FsmOwnerDefault gameObject; //owner
[RequiredField]
[Tooltip("time taken to rotate")]
public FsmFloat time;
[RequiredField]
[Tooltip("how far to rotate")]
public FsmFloat rotation;
public Vector3 targetAngles;
public PlayMakerActionsUtils.EveryFrameUpdateSelector updateType;
public override void Reset()
{
gameObject = null;
time = 1f;
rotation = 1f;
updateType = PlayMakerActionsUtils.EveryFrameUpdateSelector.OnUpdate;
}
public override void OnUpdate()
{
if (updateType == PlayMakerActionsUtils.EveryFrameUpdateSelector.OnUpdate)
{
DoRotateOverTime();
}
}
void DoRotateOverTime()
{
var owner = Fsm.GetOwnerDefaultTarget(gameObject); //get owner
if(Input.GetKeyDown(KeyCode.S)) // some condition to rotate
targetAngles = owner.transform.eulerAngles + rotation.Value * Vector3.up; // what the new angle should be
owner.transform.eulerAngles = Vector3.Lerp(owner.transform.eulerAngles, targetAngles, time.Value * Time.deltaTime); // lerp to new angle
if(owner.transform.eulerAngles == targetAngles)
{
Finish();
}
}
}
}