- Home /
How to anchor a sprite to the ground?
I have a sprite that I'm working on doing the animation for it right now. I am running into an issue where when the sprite changes animations to bend it's knees the overall sprite becomes smaller. The problem is that the sprite seems to be set to the center of the game object which results in the legs of the character lifting off the ground. Is there a way to set it so that the bottom edge of the sprite is anchored to a point on the ground so when the sprite shrinks the feet stay on the ground?
Sorry about the wording I can't think of a way to explain the issue more clearly.
Answer by TheNNation · Jan 11, 2021 at 02:13 PM
@abrinck I had the same problem, but i changed my sprites in the sprite editor so that every frame is the same size. When doing that, the center of each frame is the same, so the animation is like wanted.
Answer by LeFlop2001 · Jan 10, 2021 at 04:13 PM
You can either do a raycast downwards from the sriptes pivotpoint and set the sprites position the the raycasts hit plus the height of the sprite divided by two, or simply change the sprites pivot point in the sprite editor.
The second option is undoubtedly the correct answer, hower the first method is quite helpfull for aligning things with the ground via script and i thought id mention it.
Your answer
Follow this Question
Related Questions
how to add a sprite to an animation created in the inspector 1 Answer
Placing the sprite game object in the players position and also enable and disable it when needed 2 Answers
Animation with Transparency Floats Above Ground 1 Answer
AttachUnitySprite not available - Spine Unity 1 Answer
Transitioning between character sprites in a linear wiper like filter motion 0 Answers