AI Ram the Player

From STEAMwiki
Revision as of 17:11, 28 July 2017 by Andy (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Make sure that the enemies and the player both have Rigidbody and Collider components on them. If the 3D object is imported from TinkerCad, make a simple object like a capsule, turn off it's mesh renderer, and place your 3D object as a child of the capsule. This simple capsule will serve as the "hitbox" collider and rigidbody for the enemy agent.

Add a script "AIEnemyController" to the AI enemy.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class AIEnemyController : MonoBehaviour {

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		
	}

	void OnCollisionEnter(Collision col)
	{
		// Debug.Log(gameObject.name + " collided with " + col.gameObject.name);
		if (col.gameObject.tag == "Player")
		{
			Debug.Log("AI collided with player");
			SceneManager.LoadScene("game over");
		}
	}

 }