|
Basically I'm using the below code to rescale my character according to the power ups the user picks up (think super mario). So for example this makes the character larger. The problem I'm having is that I want to resize the character to a fixed size whereas this seems to scale it relatively. So for example if the user is small and they pick up this power up then they are scaled up but aren't anywhere as big as if they were medium sized when they picked it up.
How might I do it so it uses fixed sizes?
(comments are locked)
|
|
Try this scale demo. Put it on a cube or something. As you press Fire1 (left mouse button), the object change scale from 1 to 2 and back again next time. It uses coroutines to interpolate scale between two values with an adjustable speed.
(comments are locked)
|
|
This function needs to be in Update(), then it sould work. The Lerp will interpolate any value in localScale smoothly to the new absolute value "newScale". The only thing than can influence this is (assuming you don't have any stray scripts messing with your values), that any of the parents have scales other than 1 that keep changing.
(comments are locked)
|
|
localScale is absolute; it's not relative. Using Vector3.Lerp like that won't accomplish anything, however. The third parameter in Lerp is a float between 0 and 1, so assuming you want an animation of the scaling, you need to make a routine that animates the third parameter from 0 to 1 over time. See this for examples of coroutines which you could easily adapt to use localScale rather than position or rotation. But deltaTime is >0 (although not moving from 0 to 1), and people "misuse" a Lerp all the time for this kind of smooth interpolation. Since he is feeding the current scale into the lerp, it should work (although he might want to add a scaling factor to Time.deltaTime, to influence the smoothing speed).
Aug 17 '10 at 09:28 PM
Wolfram
@Wolfram: that kind of misuse results in a "slowdown" factor, which is often not desirable. Using a coroutine to explicitly animate between 0 and 1 allows you to control exactly what sort of curve there should be, if any, and you are guaranteed to end up exactly at the final size.
Aug 17 '10 at 10:35 PM
Eric5h5
(comments are locked)
|
