- Home /
Animating sprite resets its transform position after being moved
Hi folks. I'm using transform.Translate(Vector3.up * variable);
to move an AnimatingSprite object in world coordinates. The object is part of the Orthello 2D framework. The sprite animates through 8 images that I've published into a cocos2D sprite atlas.
My JS code is written so that when I press the space bar ("Jump") the sprite moves (+m,0,0). However every time the sprite has moved in one frame, the next frame sees the sprite reset back to its initial coordinates (0,0,0). My sprite is being one stubborn fellow!
I thought this might have to do with the animation script, but I don't know Orthello 2D well enough to understand how it cycles through the sprite atlas images.
Do I need to tell the sprite something else in order for it to remain at its newly translated coordinates? Should I make a new function that isn't Update to handle this?
JavaScript - my sprite moving code
var m : float = 1;
var obj : Transform;
function Update ()
{
if(Input.GetButton("Jump"))
{
obj.transform.Translate(Vector3.up*m);
}
}
I found this same question being asked!!
http://forum.unity3d.com/threads/165566-AnimatedSprite-with-Orthello
I'm not sure about the answer the above link gives, so I'll search further and report back.
Answer by Kai_Gil · May 07, 2013 at 12:55 PM
I can answer my own question woohoo!
" Orthello controls your position and ignores your physics. You should be able to solve this by setting your sprite.physics (in editor) to 'rigidBody' or 'NoGravity' ( after next patch also when sprite.physics = 'custom' ). "
This sorted it out, I just needed to change the Physics option in the Animating Sprite Component to Custom.