Jump to content

[Info] Scaling ground textures to in-game units


Recommended Posts

Formula:  UseScale = sqrt(DesiredScale * 300 / TextureSize)

For use with:  inst.AnimState:SetOrientation(ANIM_ORIENTATION.OnGround); inst.Transform:SetScale(scale, scale, scale)

Purpose:  Having ground textures centered on an entity scale exactly in size with in-game units rather than a seemingly arbitrary scale factor.

 

 

Say you have a texture of a circle that is 512x512 pixels for its base image that has a spriter animation of it being centered.

You want this to be exactly 28 units in-game.  28 units is 7 turfs side-by-side.

sqrt(28 * 300 / 512) = 4.050462936504912

inst.Transform:SetScale(4.050462936504912, 4.050462936504912, 4.050462936504912)

 

 

The firesuppressor_placer has an internal texture size of 1900x1900 pixels, so use 1900 for its TextureSize as an example.

 

 

Note that the scale done will make it render the edge of the texture to that scale setting, so if you have a dotted line and you wanted the dot to be over the radius, add a small fluff factor to your DesiredScale to include it.

Double note that if the texture is parented to an entity then you must remove the parent's scale factor from the desired as all parent scales are inherited to its children.

local s1, s2, s3 = parent.Transform:GetScale()
child.Transform:SetScale(scale/s1, scale/s2, scale/s3)

 

Edited by CarlZalph
Parented things.
  • Ninja 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...