- Home /
Question by
coxy17 · Aug 09, 2016 at 12:09 PM ·
quaternionlerpplaymaker
Playmaker Script Issue with Quaternion Lerp speed value
Hi
I'm writing a script for playmaker (addon for unity) and i have done a few before. My script is working except for the 'speed float' (0.1f) in the Quaternion Lerp at the end. I had this a a float variable but ive hard coded it again to see if it works and it just ignores it altogether. Doesnt matter what value is in there.
I had this working outside playmaker script using onupdate. Any ideas why this is?
Thanks
Nick
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 owner; //owner
[RequiredField]
[Tooltip("Game Object to target")]
public FsmOwnerDefault target; //owner
[Tooltip("speed")]
public FsmFloat speed;
public FsmVector3 offsetPosition;
public Space offsetPositionSpace;
public bool lookAt = false;
public FsmQuaternion targetRotation;
private Vector3 lookAtPos;
private Vector3 lookAtPosWithVertical;
private FsmVector3 upVector;
public PlayMakerActionsUtils.EveryFrameUpdateSelector updateType;
public override void Reset()
{
owner = null;
target = null;
speed = 0.1f;
offsetPosition = null;
lookAt = false;
offsetPositionSpace = Space.Self;
targetRotation = new FsmQuaternion { UseVariable = true };
upVector = new FsmVector3 { UseVariable = true};
updateType = PlayMakerActionsUtils.EveryFrameUpdateSelector.OnUpdate;
}
public override void OnEnter()
{
DoFollowObject();
}
public override void OnUpdate()
{
if (updateType == PlayMakerActionsUtils.EveryFrameUpdateSelector.OnUpdate)
{
DoFollowObject();
}
}
void DoFollowObject () {
var ownergameobject = Fsm.GetOwnerDefaultTarget(owner); //get object
var targetgameobject = Fsm.GetOwnerDefaultTarget(target); //get target
// compute position
if(offsetPositionSpace == Space.Self)
{
ownergameobject.transform.position = targetgameobject.transform.TransformPoint(offsetPosition.Value);
}
else
{
ownergameobject.transform.position = targetgameobject.transform.position + offsetPosition.Value;
}
// compute rotation
if(lookAt)
{
ownergameobject.transform.LookAt(lookAtPos, upVector.IsNone ? Vector3.up : upVector.Value);
}
else
{
//ownergameobject.transform.rotation = targetgameobject.rotation;
targetRotation.Value = targetgameobject.transform.rotation;
ownergameobject.transform.rotation = Quaternion.Lerp (targetRotation.Value, targetgameobject.transform.rotation, 0.1f * Time.deltaTime);
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612090450im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Changing rotation of Quaternion 0 Answers
Quaternion.Lerp and Vector3.MoveTowards arent smoothing 1 Answer
Vector3.lerp giving me the incorrect Quaternion 1 Answer
How to represent a gameobject's (x,y,z) rotation as a quaternion? 2 Answers
How do you smoothly transition/Lerp into a new rotation? 3 Answers