Hey guys, I am hoping someone can point me in the right direction here. I’ve been on this for a couple days now and it really doesn’t seem like it should be as difficult as it is proving to be.
I want to my character to exist in 3d space. He rotates on the Y axis. I then want to clamp the distance he is allowed to move forward, and backward. So, no matter what direction he is facing, he can only move forward, or backward a certain amount. I don’t really want a radius, because in some cases, I might want him to only be able to move backward to a certain extent, but he can move forward much further. I’ve attached a photo to explain.
It’s difficult to help you without seeing your code, but anyway, I think you should store original position and define limits while initialization (for example in Start() method). When you will change position of character at runtime you need to check limits.
Well, its acctual straight forward since we dont need code here. Its just about technique.
You should cache your current pivot point untill it gets changed, aswell as maximum forward/backward movement tolerance. Im guessing the forward direction of the player does define forward and backward movement.
Now you have to check if the player position is behind the max forward or backward and if so, snap it to the maximum. You can check it by using this line:
Thanks guys, I think we’re on the right track here. Sharp, are you referring to the vector forward, or the input with your reference to “forward” in this instance?
Here is where I am at with this script … using JS, and NGUI if that helps to clarify the way I’m doing things :
Ok perfect, then I guess my question is how do I make the connection here… Obviously you can’t add a quaternion to a Vector3, so I need to find the rotation first, then calculate forward from there, correct?
The forward can be directly accessed from the transform component by calling transform.forward.
You can calculate it yourself by rotating the normal Vector3.forward by the current rotation.