- Home /
Help! Weird Jerky Animation!
Hi there, world's biggest noob back again...
I have an enemy that enters the screen and rotates as he does so... the rotation is done via sprite animation, though, it doesn't ACTUALLY rotate.
He enters and rotates quickly, stops and animates/rotates slowly in order to shoot and then takes off quickly again. The following script I have kind of works but on the last phase the animation and speed are both really jerky... there seems to be some sort of conflict and I can't work it out. Any help would be greatly appreciated!
private var fSpeed = -3;
private var uvAnimationTileX = 2; //Here you can place the number of columns of your sheet.
//The above sheet has 4
private var uvAnimationTileY = 1; //Here you can place the number of rows of your sheet.
//The above sheet has 1
private var framesPerSecond = 10.0;
function FixedUpdate()
{
transform.Translate(fSpeed,0,0);
Phase01();
// Calculate index
var index : int = Time.time * framesPerSecond;
// repeat when exhausting all frames
index = index % (uvAnimationTileX * uvAnimationTileY);
// Size of every tile
var size = Vector2 (1.0 / uvAnimationTileX, 1.0 / uvAnimationTileY);
// split into horizontal and vertical index
var uIndex = index % uvAnimationTileX;
var vIndex = index / uvAnimationTileX;
// build offset
// v coordinate is the bottom of the image in opengl so we need to invert.
var offset = Vector2 (uIndex * size.x, 1.0 - size.y - vIndex * size.y);
renderer.material.SetTextureOffset ("_MainTex", offset);
renderer.material.SetTextureScale ("_MainTex", size);
}
function Phase01()
{
yield WaitForSeconds(1.0);
fSpeed = 0; // Slow down to shoot.
framesPerSecond = 1.0;
Phase02();
}
function Phase02()
{
yield WaitForSeconds(5.0);
fSpeed = -3; // Speed up to leave screen
framesPerSecond = 10.0;
}
Reformat please. All you do is highlight your code and click the "101010" button.
Answer by Waz · Jul 05, 2011 at 08:24 AM
You are restarting the Phase01 co-routine every single FixedUpdate (i.e. every 0.02s by default). Unlikely to be what you mean. Call Phase01 in Start() instead.
Ah, I thought it might be something to do with the update function! This is all so different to C++ (and much more fun)... lol. Thanks!
Way more fun (I hung up my C++ gloves 8 months ago after 10++ years).
Haha, I'm not surprised... I'm learning it at uni at the mo... game dev course... I keep asking the tutor if I can make my projects with Unity. LOL.
Your answer
Follow this Question
Related Questions
Playing two sprite-based animations simultaneously (Not Legacy) 2 Answers
Sprite with non-constant jitter during constant velocity movement. 2 Answers
Change animation of 4 Way Movement Sprites moving diagonally to last used non-diagonal direction? 0 Answers
Animating 2D sprite upon movement script help. 2 Answers
Why is my quad not moving in sync with its collider? 1 Answer