playMaker

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

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Vector3Lerp2 now with deltatime multiplier option
« on: February 21, 2012, 07: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: 64
Re: Vector3Lerp2 now with deltatime multiplier option
« Reply #1 on: September 27, 2014, 03: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: 15500
  • Official Playmaker Support
Re: Vector3Lerp2 now with deltatime multiplier option
« Reply #2 on: November 21, 2014, 02: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: 64
Re: Vector3Lerp2 now with deltatime multiplier option
« Reply #3 on: November 24, 2014, 04: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: 15500
  • Official Playmaker Support
Re: Vector3Lerp2 now with deltatime multiplier option
« Reply #4 on: December 02, 2014, 01:37:51 AM »
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: 15500
  • Official Playmaker Support
Re: Vector3Lerp2 now with deltatime multiplier option
« Reply #6 on: December 05, 2014, 01:49:42 AM »
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
    • AL Games
Re: Vector3Lerp2 now with deltatime multiplier option
« Reply #7 on: December 07, 2014, 12:53:23 PM »
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: 15500
  • Official Playmaker Support
Re: Vector3Lerp2 now with deltatime multiplier option
« Reply #8 on: December 08, 2014, 03: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
    • AL Games
Re: Vector3Lerp2 now with deltatime multiplier option
« Reply #9 on: December 10, 2014, 05: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: 15500
  • Official Playmaker Support
Re: Vector3Lerp2 now with deltatime multiplier option
« Reply #10 on: December 11, 2014, 01:47:49 AM »
Hi,

 Thanks for reminding me about the trello task :)

 Bye,

 Jean