- Home /
Question by
skylerkingdev · Apr 24, 2017 at 02:48 PM ·
scripting problempositioninglocalpositionmathf.clamp
Clamping local movement
What is the proper approach for clamping a position in local space? I want to clamp the local forward vector so no matter which direction my object is facing it can only move backward between -5 units and 0 units.
void Update ()
{
if (dragging)
{
Vector3 targetPos = transform.localPosition;
targetPos.z += Input.GetAxis ("Mouse Y");
targetPos.z = Mathf.Clamp (targetPos.z, -5, 0);
transform.localPosition = Vector3.MoveTowards (transform.localPosition, targetPos, 3 * Time.deltaTime);
}
}
Comment
Your answer
Follow this Question
Related Questions
Chambering new round script not working 0 Answers
point A to Point B 0 Answers
I don't like Matf.clamp what to do ? 2 Answers
Setting the FPS Camera to a certain position 0 Answers
Put the text on Collectibles position ! 0 Answers