- Home /
Lerp to position in instantiated prefab?
Hey guys,
I'm wondering if it's possible to Lerp to a target position in an instantiated prefab. Maybe with a target that has an appropriate tag? Not sure. The target position would be on a particular axis. X or Y.
I'm new to Lerp so I'm trying to feel my way around.
Thanks in advance for any and all help!
Lerp is just a weighted average: Lerp(a,b,0.5)
makes a number 1/2 way from a to b. The exact same thing as (a+b)/2. Best to start by thinking if you want to move smoothly, move using "physics" speed-up, etc... . Once you know what you want to get, look for solutions.
Owen, Thanks for the info! I need to check into that also. Speed, physics, etc. I know I ran across this before something that would be the equivalent to applying a function curve. Like ease in/out. Can't remember where I saw that.
Answer by Justin Warner · Mar 29, 2011 at 02:05 PM
http://unity3d.com/support/documentation/ScriptReference/Vector3.Lerp.html
Example code shows how to make an object move somewhere (Hint, read the green text).
http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html
Look for number 3.
This should help. Reason for this is so you can look around the API and get a feel on how to use it, as that's how you'll learn most of your scripting...
So... get target object, put that in a spot on the lerp, then get the actual target, put that on the other lerp, then add in the time to do it... now I don't know how you want this to start... But I'll assume it is when it's instantiated... So, put that in an function Awake(), on to the actual target, and then you don't really need the second link, as you can do this.gameObject, and then the other object to move to it is already there... So just make that a var...
But hope this helps =).
Thanks for the info, Justin! I appreciate it. I'll have to mess around with that a bit so much capability in Unity!
In the end, I might end up Lerping on a grid. Just looking for the best solution. The player-movement grid will be active over a tiled-texture (grid) background. I guess the grid would be the most accurate overall, being that the player can continue on in the scene for an unlimited distance.
Still have a lot of research to do.
Yes, Unity is vast, however, the problem, which you seem to overcome, is actually asking the RIGHT question, but mostly, RESEARCH, which contributes to questions, and actually understanding answers... But yes, as long as you look around, and put forth effort, anyone can help you =).