I’m currently trying to make a small space game with my friend but I have encountered a problem pretty early on. To give the illusion that the ship is moving I have a texture behind it that I plan to offset. But I don’t know how to offset that texture based on the direction of the ship. For example, if the ships rotation is 60 and I accelerate, how do I get the texture to scroll in the opposite direction.
Say you have a top-down view, so x and z are the world coords you can see. If you rotate the ship, transform.forward * speed is the ship’s motion and also the slide background amount. Texture offsets work “backwards” (not a Unity thing – they do for real,) so adding forward to your offset slides the texture backwards.
Offsets are an x/y, so shift offset by your speed something like:
Vector2 OFF = renderer.material.mainTextureOffset; // pull it out to save typing?
OFF.x += transform.forward.x*speed * scaleFactor;
OFF.y += transform.forward.z*speed * scaleFactor;
renderer.material.mainTextureOffset = OFF;
Texture offsets think 0-1 is an entire screen, so scaleFactor is something like 1/worldUnitsOfEntireMap.
You may have to adjust +/- of y/z if you have a different camera view, by doing a few experiments going directly right and up. Make sure you have the material set to tile.
A massive thanks for that answer, after all my trouble trying to solve it with trigonometry it’s a big surprise how simple the answer is.