These two days have been doing a roaming, roaming code, all over the web, there are, but in the process of roaming there is a problem, that is, after hitting the wall will wear a wall, or will rebound, the camera has been shaking, so it looks very uncomfortable,
Roaming program is not much, there are many, I use two kinds:
1. Use the sliding offset to control the movement, which consists of three
The first one is the Input.getmousebuttondown (0) and Input.getmousebutton (0) of the mouse to calculate the offset;
The second is the use of virtual axes
float Offetx = Input.getaxis ("Mouse X");//swipe left and right
float offety = Input.getaxis ("Mouse Y");//swipe up or down
To control movement and rotation;
Third, the use is the mobile platform under the finger slide, this also has a lot of, also can use
Fingergestures plug-in;
This can take a look at Xuanhusung's blog, telling the details, http://www.xuanyusong.com/archives/1869
can also use Input.gettouch (0) finger slide;
In short, a sentence is to use the amount of deviation to control movement and rotation;
2. Prevent the camera from piercing the wall:
All two objects that collide are added collider, and the moving object is set to add a rigid body (a capsule child object is added to the camera, and collider and Rigidbody are loaded capsule's parent), But to prevent the wall from going through the rigidbody component of the constraints attribute, respectively, there are Freeze Position (x, Y, z) and Freeze Rotation (x, Y, z), fixed position and angle,Freeze Rotation ( X, Y, z) which axis to hook on, after the collision does not exceed which axis rotates, Freeze Position (z/y) controls the position, prevents the wall, the z axis cannot hook , so after the collision will not wear the wall.
3. Prevent collision Bounce
This is not very difficult, just can't think of this problem where, you see after you will understand, in fact, as a rigid body, gameobject movement, the value of rigidbody.velocity is not a vector (0,0,0), as a rigid body, after the collision will rebound, So will be moving, toward the direction of rebound, so very upset, but we can be rigidbody.velocity 0, no speed will not rebound, because it is physical characteristics, so do not write in the update,
void Fixedupdate ()
{
This. Getcomponent<rigidbody> (). rigidbody.velocity = new Vector3 (0, 0, 0);
}
This is the perfect solution, if there is a problem, come on we continue to discuss
This article is from the "Unity_3d Technology discussion" blog, please be sure to keep this source http://caoliyong.blog.51cto.com/9944020/1737528
Unity3d scene roaming and collision prevention bounce