- Home /
Question by
n9ne · Feb 02, 2015 at 01:03 PM ·
2d2d game2d-platformery-axis
Prevent Y-axis Movement In 2D
So iam spawning an object that have a box collider and no rigidbody and it have animation , and every time it get spawned it moves on the y-axis so how to prevent this move ??
Comment
Is the unwanted movement being caused by the animation? $$anonymous$$aybe you just need to uncheck 'Apply Root $$anonymous$$otion' in the animator?
Best Answer
Answer by ironblock · Feb 04, 2015 at 11:00 AM
this is a simple script that clamps objects.
using UnityEngine;
using System.Collections;
public class limitPlayer : MonoBehaviour {
public float minimumX = -10f;
public float maximumX =10f;
public float minimumY = -9.8f;
public float maximumY =9.8f;
public float minimumZ = -20f;
public float maximumZ =20f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.position = new Vector3 (Mathf.Clamp (transform.position.x, minimumX, maximumX), Mathf.Clamp (transform.position.y, minimumY, maximumY), Mathf.Clamp (transform.position.z, minimumZ, maximumZ));
}
}
Your answer