- Home /
movement transform limit ?
ask againn.. need help when i use this scipt
var robot: Transform;
private var checkgui= false;
private var2 checkgui= false;
function Update()
if ( checkgui==true) Input.GetKeyDown(KeyCode.Q))
{
bodyBase();
}
if ( checkgui2==true) Input.GetKeyDown(KeyCode.E))
{
bodyBase1();
}
.....
function bodyBase() {
robot.transform.Translate(Vector3(0,2f,0));
robot.transform.position.x = Mathf.Clamp(transform.position.y, 75, 0);
}
function bodyBase1() {
robot.transform.Translate(Vector3(0,-2f,0));
robot.transform.position.x = Mathf.Clamp(transform.position.y, 90, 0);
}
my object move directly to position 90f (press Q) or 75 (press E),how to move that object smoothly if press Q or E? or dont move directly to limit position?
Thanks.
Your parameters to clamp are in the wrong order. It's (`value`, $$anonymous$$
, max
).
how to fix that ?
robot.transform.Translate(Vector3(-2 ,0,0));
robot.transform.position.x = $$anonymous$$athf.Clamp(transform.position.x, 9.5f, -9.5f);
still move not smoothly
Answer by timdan · May 28, 2014 at 06:43 PM
This line of code....
robot.transform.position.x = Mathf.Clamp(transform.position.y, 75,
0);
..is changing the x value, not just limiting it. You'll need to create a variable for you maximum x value, then clamp the variable before using it in your translation.
Your answer

Follow this Question
Related Questions
iTween.ShakePosition freezes Rotation 0 Answers
c# getting gameobject to look at its child that is an empty gameobject (only transform component)? 1 Answer
How would I clamp a balance board? Mathf.clamp does not work! 1 Answer
Object reference error even though I've assigned the object in 1 Answer
Dynamically updating a Coroutine's parameters every frame 1 Answer