How do I clamp an object's movement so that it can't move in its local y axis?
To elaborate on the title, the gameObject is located on a spherical world, so clamping it from moving on the world y axis will not work as I need the object to be able to move all around the globe (i.e. varying x, y and z). This clamping is for the AI (not the Player) and is necessary because the movement will be governed by two things:
an artificial gravity created by addForce'ing
a script which causes the object to try and "catch" a projectile. I haven't worked it out completely yet, but the following almost works although it causes the AI to flow upwards from the surface in a jittery fashion when the target projectile's velocity is facing away from the AI object:
Ray ray = new Ray (target.transform.position, target.gameObject.GetComponent<Rigidbody> ().velocity); RaycastHit hit; if (Physics.Raycast (ray, out hit)) { transform.position = Vector3.MoveTowards (transform.position, hit.point, speed * Time.deltaTime);
I hope this is clear enough, if not please let me know how I can clear it up for You. Thank You for the help in advance!
EDIT: clamping the movement within a radius of the sphere is another way to think about it, still no idea how though..
Your answer
