- Home /
Animated UVs dependent on joystick input - Scrolling BG
Me again!
I have the following code that I am using to animate the bg in my race game. It works well, but as the variable fOffset is updated every frame, thanks to the Time.time, when I change directions, the fOffset has changed and the BG skips. How would I go about setting a variable to match fOffset at the point where I let go of the joystick and have it not update every frame as fOffset does?
Sorry if this is very noobish... I am TERRIBLE at math and a noob coder ;-)
private var fScrollSpeed : float = 0.5;
private var fOffset : float;
private var fCurrentPosition : float;
function Update ()
{
// Move background when steering car by animating UVs
if (Player01.g_bPlayerOneIsTurningLeft)
{
fOffset = Time.time * fScrollSpeed;
renderer.material.mainTextureOffset = Vector2 (fOffset, 0);
}
else if (Player01.g_bPlayerOneIsTurningRight)
{
fOffset = Time.time * fScrollSpeed;
renderer.material.mainTextureOffset = Vector2 (fOffset, 0);
}
else
{
renderer.material.mainTextureOffset = renderer.material.GetTextureOffset("_MainTex");
}
}
Comment
Best Answer
Answer by POLYGAMe · Feb 03, 2012 at 04:18 AM
Fixed it for anyone else!!!
private var fScrollSpeed : float = 0.5;
private var fOffset : float;
var fCurrentXPosition : float;
function Update ()
{
// Move background when steering car by animating UVs
if (Player01.g_bPlayerOneIsTurningLeft)
{
fOffset -= fScrollSpeed * Time.deltaTime;
}
else if (Player01.g_bPlayerOneIsTurningRight)
{
fOffset += fScrollSpeed * Time.deltaTime;
}
renderer.material.mainTextureOffset = Vector2 (fOffset, 0);
}
Your answer
