C # Moving and restricting moving distances

Source: Internet
Author: User

public class Planemove:monobehaviour {

H: Horizontal Direction control, V: Front and rear direction control

float h,v;

Speed: Aircraft flight speeds

public float speed;

Use this for initialization

void Start () {}

Update is called once per frame

void Update () {

Values in horizontal direction

h = Input.getaxis ("horizontal");

Values in the vertical direction

v = Input.getaxis ("Vertical");

Move vertically one metre per second

Transform.position +=-v * New Vector3 (0,0,1f) * speed * time.deltatime;

Horizontal direction One metre per second

Transform.position +=-h * New Vector3 (1f,0,0) * speed * time.deltatime;

Limit coordinates x axis -3.5~3.5,z axis -10~1

Vector3 pos = transform.position;

float x = pos.x;

float z = pos.z;

x = Mathf.clamp (x, -3.5f, 3.5f);

z = Mathf.clamp (z, -10f, 1f);

Pos. Set (x, Pos.y, z);

Transform.position = pos;

}

}

C # Moving and restricting moving distances

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.