playMaker

Author Topic: Clamped lerp follow  (Read 1639 times)

Red

  • Hero Member
  • *****
  • Posts: 563
    • View Profile
Clamped lerp follow
« on: March 30, 2015, 03:10:58 PM »
EDIT: April 2, 2015. New updated action.
http://hutonggames.com/playmakerforum/index.php?topic=9986.msg47453#msg47453

Here's an action that will make an object follow another.

The way this works is you set up the object, tell it what object to follow, how fast it should move, what distance the object should be from it's target for it to activate and also a clamping mechanism to limit the area it's allowed to move within.

The values for the area are inputted with float values. These are world-space values at this time.

If the clamping values are set to "none" then it will effectively not be limited by that value. So if you want to have it not move lower than a certain point on the X axis but want it to follow as far on the positive, set the "X Max" value to "none" and the "X Min" value to the certain point. This works in all three axes as it is essentially a vector3 lerping function (but at this time I had to break the three axes up to clamp them. If there's a better way to do this, please let me know.)

Could be a starting point for a basic AI system or a camera controller or something like that. This does not control rotation, however. Just position.

I understand this is a little more specialized as the distance checking could be done external to the action but I kinda added it in for the heck of it. If the consensus is that I should remove it for this then I can easily oblige.

As this is another script that I am learning C# with, if you have any suggestions on how to refine or streamline it to be more elegant I'm more than eager to hear your thoughts.
« Last Edit: April 02, 2015, 10:30:32 AM by Red »

Red

  • Hero Member
  • *****
  • Posts: 563
    • View Profile
Re: Clamped lerp follow
« Reply #1 on: April 02, 2015, 10:28:05 AM »
A bit of tweaking. Changed the if statements that test for clamping values having data to a conditional statement instead (and it makes it nicer to look at as well.)

Minor tweak I guess but if it helps shave down the code maybe it will shave down the memory consumption.