Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: coxy17 on August 06, 2016, 07:41:03 PM

Title: Custom Script Lerp speed issue [SOLVED]
Post by: coxy17 on August 06, 2016, 07:41:03 PM
hi

i have the following script which works so far to follow a gameobject. I just cant get one part of it to work with playmaker FSM. The script works fine before i started writing this script.

the problem is only with the time on line 97 and where it has... 0.1f
Quote
ownergameobject.transform.rotation  = Quaternion.Lerp (targetRotation.Value, targetgameobject.transform.rotation, 0.1f * Time.deltaTime);

Whatever i specify in this e.g. from 0.1 to 0.9 i cant get a delay to work. it seems to be ignoring the value. Not sure why? this works out of playmaker so i guess its something to do with playmaker causing this.

Nick

Code: [Select]
// (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 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);

}



}

}
}
Title: Re: Custom Script Lerp speed issue
Post by: jeanfabre on August 10, 2016, 04:01:40 AM
Hi,

 ok, you where very close :)

 you mixed up the targetGameobject and the ownerGameObject when setting the targetRotation.Value

you should have
Code: [Select]
targetRotation.Value = ownergameobject.transform.rotation;

ownergameobject.transform.rotation  = Quaternion.Lerp (targetRotation.Value, targetgameobject.transform.rotation, 0.1f * Time.deltaTime);



 because your targetRotation represent the current animated rotation. Maybe you could rename the targetRotation to "AnimatedRotation" or something if you find this confusing.

Bye,

 Jean

Title: Re: Custom Script Lerp speed issue
Post by: coxy17 on August 11, 2016, 02:21:29 PM
Thanks again Jean!!! yeah now you pointed it out it so obvious, i will rename it. Once i have done all my scripts then ill send you a tweet.

Nick
Title: Re: Custom Script Lerp speed issue [SOLVED]
Post by: jeanfabre on August 12, 2016, 04:25:17 AM
Hi,

 Excellent:)

 Bye,

 Jean