playMaker

Author Topic: Vector3Lerp2 now with deltatime multiplier option  (Read 4876 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14058
  • Official Playmaker Support
    • View Profile
Vector3Lerp2 now with deltatime multiplier option
« on: February 21, 2012, 05:20:11 AM »
Hi,

 Sometimes it becomes necessary to lerp vector position against deltatime. This version of Vector3Lerp implements a flag to just do that.

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2012. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Vector3)]
[Tooltip("Linearly interpolates between 2 vectors. it also lets you lerp against deltatime")]
public class Vector3Lerp2 : FsmStateAction
{
[RequiredField]
[Tooltip("First Vector.")]
public FsmVector3 fromVector;

[RequiredField]
[Tooltip("Second Vector.")]
public FsmVector3 toVector;

[RequiredField]
[Tooltip("Interpolate between From Vector and ToVector by this amount. Value is clamped to 0-1 range. 0 = From Vector; 1 = To Vector; 0.5 = half way between.")]
public FsmFloat amount;

[Tooltip("amount is multiplied by the deltatime")]
public bool lerpAgainstDeltaTime;


[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("Store the result in this vector variable.")]
public FsmVector3 storeResult;

[Tooltip("Repeat every frame. Useful if any of the values are changing.")]
public bool everyFrame;

public override void Reset()
{
fromVector = new FsmVector3 { UseVariable = true };
toVector = new FsmVector3 { UseVariable = true };
storeResult = null;
lerpAgainstDeltaTime = false;
everyFrame = true;
}

public override void OnEnter()
{
DoVector3Lerp();

if (!everyFrame)
{
Finish();
}
}

public override void OnUpdate()
{
DoVector3Lerp();
}

void DoVector3Lerp()
{
if (lerpAgainstDeltaTime)
{
storeResult.Value = Vector3.Lerp(fromVector.Value, toVector.Value, Time.deltaTime*amount.Value);
}else{
storeResult.Value = Vector3.Lerp(fromVector.Value, toVector.Value, amount.Value);
}
}
}
}



 Bye,

 Jean

MS80

  • Junior Playmaker
  • **
  • Posts: 63
    • View Profile
Re: Vector3Lerp2 now with deltatime multiplier option
« Reply #1 on: September 27, 2014, 12:55:04 PM »
Great flag, thanks Jean!! This is really useful if you want to have smooth movement, damping etc.
Please add this to the standard vector3/vector2/float lerp action

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14058
  • Official Playmaker Support
    • View Profile
Re: Vector3Lerp2 now with deltatime multiplier option
« Reply #2 on: November 21, 2014, 12:50:32 AM »
Hi,

 ok, I have updated all the ecosystem actions I think could get this nice additions, let me know if you see others.


 Bye,

 Jean

MS80

  • Junior Playmaker
  • **
  • Posts: 63
    • View Profile
Re: Vector3Lerp2 now with deltatime multiplier option
« Reply #3 on: November 24, 2014, 02:34:45 PM »
Great! Thanks Jean!

I saw these actions without flag deltatime:
- float lerp
- float lerp advanced
- quaternation slerp

I think this feature is useful for many actions! This is the only way to make sure behavior is the same while running on different framerates (like per second feature). Actions depending on time could benefit of deltatime, like "move towards" or "rotate towards".

btw, I really enjoy using the ecobrowser!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14058
  • Official Playmaker Support
    • View Profile
Re: Vector3Lerp2 now with deltatime multiplier option
« Reply #4 on: December 01, 2014, 11:37:51 PM »
Hi,

 ok, FloatLerp is done

Float Lerp advanced has this option it's in the type of interpolation, choose "deltaTime".

and Quaternion Slerp was already with this addition, maybe I did it and forgot to post here right after .

Bye,

 Jean


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14058
  • Official Playmaker Support
    • View Profile
Re: Vector3Lerp2 now with deltatime multiplier option
« Reply #6 on: December 04, 2014, 11:49:42 PM »
Hi,

 You need to delete the action and download it again. The next version of the ecosystem will allow you to delete from the browser itself, so it will be easier to do these updates. And I am working actively on a versioning systems so that I can even detect and prompt you for updates automatically.

 Bye,

 Jean

ermak

  • Junior Playmaker
  • **
  • Posts: 60
    • View Profile
    • AL Games
Re: Vector3Lerp2 now with deltatime multiplier option
« Reply #7 on: December 07, 2014, 10:53:23 AM »
Hi,

I delete QuaternionSlerp action and download it again... but there are is
no checkbox for "Lerp Against Delta Time". Maybe this checkbox is only for
Lerp and Slerp use DeltaTime by default, without checkbox?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14058
  • Official Playmaker Support
    • View Profile
Re: Vector3Lerp2 now with deltatime multiplier option
« Reply #8 on: December 08, 2014, 01:28:40 AM »
d'oh :)

 I forgot to update the Custom Editor. re download please :)

 Delete manually the script "QuaternionLerpCustomEditor" if necessary.

That's a good case for me to take in consideration for more intuitive updates from the the Ecosystem.

 Bye,

 Jean

ermak

  • Junior Playmaker
  • **
  • Posts: 60
    • View Profile
    • AL Games
Re: Vector3Lerp2 now with deltatime multiplier option
« Reply #9 on: December 10, 2014, 03:47:35 AM »
Finally "DeltaTime" Lerp/Slerp/Vector3/Quaternion... :)
That was very important for multiplayer games.

You can move this Trello Card to "DONE"
https://trello.com/c/Sd1J0JQV/23-quaternion-package-update

Thank you so much!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14058
  • Official Playmaker Support
    • View Profile
Re: Vector3Lerp2 now with deltatime multiplier option
« Reply #10 on: December 10, 2014, 11:47:49 PM »
Hi,

 Thanks for reminding me about the trello task :)

 Bye,

 Jean