Tower Defense TDTK enemies move to target steering

Source: Internet
Author: User

using Unityengine;
Using System.Collections;


public class Enimiy:monobehaviour {
public Transform target;
public float movespeed = 1;
Private Transform thist;



void Start () {

}

After the game has been awakened, assign value

void Awake () {
Thist = This.transform;
}


void Update () {

moveToPoint (target.position);

}

private float rotatespd =5f;

Slerp slowly turning to the target

void moveToPoint (Vector3 point) {
quaternion Wanterot = quaternion.lookrotation (point-thist.position);
Thist.rotation = Quaternion.slerp (thist.rotation, Wanterot, rotatespd * time.deltatime);

Normalized is to turn Vector3 into a value of size 1.

Vector3 dir = (point-thist.position). normalized;
Thist.translate (dir * movespeed * time.deltatime, Space.world);
}
}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Tower Defense TDTK enemies move to target steering

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.