- Home /
Simple Maths Problem - Help!
Okay, I've got a plane with a texture applied to it, and I want to scale the plane according to a sphere collider I have. BEFORE you read ahead, please note that the texture fits perfectly around the sphere collider (texture is a ring) at radius 10 so I have been working around '10', so for example, if the radius equals 9, then Scale / 9 * 10 = The New Scale for that current radius. The problem I'm having is that, at radius 10, the texture fits fine. But if I choose anything lower than 10, so, 9 - the texture grows bigger, not smaller. And vise versa, radius 11 - texture is smaller.
Code:
var RadiusObject : Transform; private var CurrentSize : float;
private var ScaleX = 2; // These are the texture size when they fit perfectly at 10 private var ScaleY = 0; //--not worried about this, its always 0--\\ private var ScaleZ = 2.3;
private var ScaleXDiv : float = 0; //These are the new scale size private var ScaleYDiv : float = 0; private var ScaleZDiv : float = 0;
function Update () { CurrentSize = collider.radius;
ScaleXDiv = (ScaleX / CurrentSize) * 10;
ScaleZDiv = (ScaleZ / CurrentSize) * 10;
RadiusObject.transform.localScale = Vector3(ScaleXDiv,ScaleY,ScaleZDiv);
}
Answer by oliver-jones · Nov 21, 2010 at 01:05 AM
Solved it my self ... Soo Simple, haha I just had to reverse the formula (with some slight moderation:
var RadiusObject : Transform; private var CurrentSize : float;
private var ScaleX = 2; private var ScaleY = 0; private var ScaleZ = 2.3;
private var ScaleXDiv : float = 0; private var ScaleYDiv : float = 0; private var ScaleZDiv : float = 0;
private var ScaleXNew : float = 0; private var ScaleZNew : float = 0;
function Update () { CurrentSize = collider.radius;
ScaleXDiv = (ScaleX * CurrentSize);
ScaleXNew = ScaleXDiv / 10;
ScaleZDiv = (ScaleZ * CurrentSize);
ScaleZNew = ScaleZDiv / 10;
RadiusObject.transform.localScale = Vector3(ScaleXNew,ScaleY,ScaleZNew);
}
Your answer
Follow this Question
Related Questions
how to scale object to fit inside a room 1 Answer
Sprite doesn't flip correctly. 1 Answer
Ignore Collision Temporarily 1 Answer
Normalise a value 2 Answers
Shear transformation using GameObject transformations 2 Answers