Question by
8thegamingninja · Mar 13, 2018 at 05:11 AM ·
c#aiai problemsram
How do I make an AI(cube) that follows and rams the player?
I have looked at questions that are similar, but I couldn't find an answer that worked for me. I want the AI to follow the player, then ram, trying to knock it off of the arena. This is the best code I found, but unity gives me errors that I don't know how to fix. I think this is C# \/\/
using UnityEngine; using System.Collections;
public class FollowScript : MonoBehaviour { var target = Transform; //the enemy's target var moveSpeed = 3; //move speed var rotationSpeed = 3; //speed of turning
var myTransform : Transform; //current transform data of this enemy
function Awake()
{
myTransform = transform; //cache transform data for easy access/preformance
}
function Start()
{
target = GameObject.FindWithTag("Player").transform; //target the player
}
function Update () {
//rotate to look at the player
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
//move towards the player
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
}
Comment
Your answer
Follow this Question
Related Questions
make AI to carry objects 1 Answer
How do I make an enemy chase the player with a C script? 3 Answers
Issue with basic enemy AI script. 1 Answer
AI being scared of player. 0 Answers