This question was
closed Feb 19, 2018 at 11:09 AM by
unity_S0ZCLiVP1XXH-w for the following reason:
Question is off-topic or not relevant
Game Object jumps to z-axis
I make a game for android and I need a game object moving on x and y axis. When I start moving my Target object it moves to canvas in z axes and moves only around it here s my script [System.Serializable] public class Boundary { public float xMin, xMax, yMin, yMax; }
public class TargetMoving : MonoBehaviour
{
public float speed;
public Boundary boundary;
Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
if (Time.time > 1.0)
if (Input.GetMouseButton(0))
{
float moveHorizontal = CnInputManager.GetAxis("Mouse X");
float moveVertical = CnInputManager.GetAxis("Mouse Y");
Vector3 movement = new Vector3(moveHorizontal, moveVertical, 0.0f);
rb.velocity = movement * speed;
rb.position = new Vector3
(
Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax),
Mathf.Clamp(rb.position.y, boundary.yMin, boundary.yMax),
0.0f
);
}
}
}
Sorry for my English. 5 hours working and I got this. Please help
Comment
Follow this Question
Related Questions
Need help with limited movement with mathf clamp 2 Answers
How do you change your z axis in a movement script. 1 Answer
moving an object continuously between waypoints 0 Answers
C# finding the axis of a characterobject 0 Answers
Jump is higher then normal 0 Answers