#animation making player snap to original position

1 messages · Page 1 of 1 (latest)

full lion
#

Always make sure that your animator is either not on a root object, or has root motion disabled. Or both.

pine basin
#

where can i find it

full lion
#

Find what, the animator component?
...presumably on the root object of your character

queen blaze
#

the root

#

this is my second acc

pine basin
full lion
#

show a screenshot of your animator and the hierarchy.

pine basin
#

k

#

this is it

full lion
#

Sorry, I meant your Animator component.
Also is this really the animator in question? Because it doesn't look like it belongs to a player character

pine basin
#

it is for the player(larry)

#

\

full lion
#

What object is the component on?

pine basin
#

the player

pine basin
full lion
#

"the player" is not helpful. on which object in your hierarchy is the animator component?

pine basin
#

larry

full lion
#

okay first off, you shouldn't use Animators for UI for performance reasons.
second, you'd likely be better off just moving your player between levels (which I assume the above animator is for) through code.
third, where are the "emotes" you talked about, inside your animator?

pine basin
pine basin
full lion
full lion
#

It usually is a good idea to separate logic and animations.
For animations, that means that you want an empty object as the root which handles movement, and for the Animator to be a child of that empty object.
Not sure whether that would be the right thing for you, considering you use the animator to move the object between fixed places. But as I said, moving through code would be a better solution.

pine basin
#

how can i move through code?

full lion
#

there's several methods for that, and there's tutorials for those methods online.

pine basin
#

can you recomend one please

full lion
#

look into Vector3.Lerp or Vector3.SmoothDamp.

#

If you need move sophisticated movement, a waypoint system of sorts could work as well.

pine basin
#

the thing is how can i get the right value of the vector3 so he moves to the right placde

#

place*

full lion
#

you already have object representing those positions, don't you?
just use them.

full lion
pine basin
#

i mean how do i get the right value of the vector

#

you know what

#

i think i know

#

ill try it

#

if i have any problems ill ask you

#

thanks for helping me

pine basin
#

bro

#

@full lion should i delete this post and make another one cuz i ran into another problem

#

sorry for pinging you

#

the problem is that i cant get the lerp to work ill provide the code

#
{
    [SerializeField] private Transform player_t;
    [SerializeField] private Transform tut_t;
    [SerializeField] private Transform lvl1_t;
    
    [SerializeField] private float elapsedTime;
    [SerializeField] private float Duration = 1f;
    private bool ontut = true;
   
    void Update()
    {
        
        if (ontut == true && Input.GetKeyDown(KeyCode.RightArrow))
        {
            float percentageComplete = elapsedTime / Duration;
            player_t.position = Vector3.Lerp(tut_t.position, lvl1_t.position, percentageComplete);
            elapsedTime += Time.deltaTime;
            
        }

        
    }
}
#

the problem is that he doesnt reach the destination

#

i know why but i can fix it

#

its because i have the code serounded by an if statement

#

but i want the player to move when you press the right arrow only

full lion
#

GetKeyDown will only be true for a single frame when the key is initially pressed down.
So your player will only move a tiny bit every time you press the right arrow key.

pine basin
#

so what should i use instead?

full lion
#

use a coroutine to actually move your player from point to point. start that coroutine when the button is pressed

pine basin
#

ill ty tomorow its 1:30 AM

pine basin
#
    {
        while (Vector3.Distance(player_t.position, lvl1_t.position) > 0.01f)
        {
            player_t.position = Vector3.Lerp(player_t.position, lvl1_t.position, 3 * Time.deltaTime);
            yield return null;
        }






       
    }```