|
|
|
|  NPC mit LookAt NPC verfolgt Spieler und schaut ihn an (wenn auf derselben Ebene) (Lookat & movedirection.z=1) | | | |
 ![Einen Kommentar (einer Stelle[markiert]) hinzufügen](imgs/iconaddobject.gif)
| /*
NPC Follow LookAt */
var speed = 1; var jumpSpeed = 8.0; var gravity = 20.0;
var spieler:GameObject;
private var moveDirection = Vector3.zero; private var grounded : boolean = false;
function OnControllerColliderHit (hit : ControllerColliderHit) { // CharacterController.OnControllerColliderHit.html /* controller The controller that hit the collider collider The collider that was hit by the controller rigidbody The rigidbody that was hit by the controller. gameObject The game object that was hit by the controller. transform The transform that was hit by the controller. point The impact point in world space normal The normal of the surface we collided with in world space moveDirection Approximately the direction from the center of the capsule to the point we touch. moveLength */ // hit? // print(hit); // hit from which direction? // print(hit.moveDirection); // hitted object // print(hit.gameObject.name); if (hit.gameObject.name=="feind") { // Destroy(hit.gameObject); print("du bist tot"); } if (hit.gameObject.name=="Pille") { Destroy(hit.gameObject); // print("du bist tot"); } }
function OnTriggerEnter (other : Collider) { // Destroy(other.gameObject); print("OnTriggerEnter "+other.gameObject); }
// house keeping functions function FixedUpdate() {
// alle pillen weg // gewonnen var Pillen=GameObject.Find("Pillen");
// print("-"+Pillen.transform.childCount);
if (Pillen.transform.childCount==0) { print("next level"); }
if (grounded) {
moveDirection=new Vector3(0.0,0,0);
/* // ... if (spieler.transform.position.x>transform.position.x) { moveDirection.x=1; } if (spieler.transform.position.x { moveDirection.x=-1; } if (spieler.transform.position.z>transform.position.z) { moveDirection.z=1; } if (spieler.transform.position.z { moveDirection.z=-1; } */ moveDirection.z=1; transform.LookAt(spieler.transform,Vector3.up);
moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed;
}
// Apply gravity moveDirection.y -= gravity * Time.deltaTime;
// Move the controller var controller : CharacterController = GetComponent(CharacterController); var flags = controller.Move(moveDirection * Time.deltaTime); grounded = (flags & CollisionFlags.CollidedBelow) != 0; }
@script RequireComponent(CharacterController) | | | |
|
|
|