#animation making player snap to original position
1 messages · Page 1 of 1 (latest)
where can i find it
Find what, the animator component?
...presumably on the root object of your character
ive been trying for a week and i cant figure it out please help
show a screenshot of your animator and the hierarchy.
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
What object is the component on?
the player
should i not put it there?
"the player" is not helpful. on which object in your hierarchy is the animator component?
larry
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?
the emote is the "enter level"
i have no idea how to make him move through code
ig make sure that the corresponding animation does not modify the object's transform 🤷♂️
it doesnt
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.
how can i move through code?
there's several methods for that, and there's tutorials for those methods online.
can you recomend one please
look into Vector3.Lerp or Vector3.SmoothDamp.
If you need move sophisticated movement, a waypoint system of sorts could work as well.
the thing is how can i get the right value of the vector3 so he moves to the right placde
place*
you already have object representing those positions, don't you?
just use them.
how tho?
see above
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
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
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.
so what should i use instead?
use a coroutine to actually move your player from point to point. start that coroutine when the button is pressed
ill ty tomorow its 1:30 AM
{
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;
}
}```