About the Y Lock.
I've been busy with college recently so I haven't done much with it, but I will give an update later today at the very least.
seen from Belgium

seen from Malaysia
seen from United States
seen from China
seen from United States

seen from United States
seen from United Kingdom
seen from China
seen from United States
seen from United States
seen from Georgia
seen from Türkiye
seen from Sweden
seen from Singapore
seen from South Korea
seen from China
seen from China
seen from United States
seen from Russia
seen from Maldives
About the Y Lock.
I've been busy with college recently so I haven't done much with it, but I will give an update later today at the very least.
Enemy AI (Alert Distance) - Now with yLock Capabilities!
Note: yLock allows you to stop the enemy from chasing you along the y axis
1). This is an enemy AI that activates when the Player comes within a certain distance of it, chasing and shooting at the player.
2). For this script, you need a player tagged as Player, an enemy with isTrigger checked, and a bullet (make sure it has a rigidbody, gravity turned off, isTrigger checked, and the bullet script from here.
3). Drag this script onto the enemy:
var player : Transform;
var distanceToActivate : int = 15;
var rotationSpeed : int = 5;
var moveSpeed : int = 2;
var bullet: Rigidbody;
var timer : int = 0;
var shootTime : int = 40;
var canShoot : boolean = true;
var yLocked : boolean = true;
//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 Update()
{
if(Vector3.Distance(player.transform.position, transform.position) < distanceToActivate)
{
timer++;
if(yLocked)
{
var newPos = new Vector3(player.position.x, myTransform.position.y, player.position.z);
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(newPos - myTransform.position), rotationSpeed*Time.deltaTime);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
else
{
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(player.position - myTransform.position), rotationSpeed*Time.deltaTime);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
if(timer % shootTime == 0 && canShoot){
timer = 0;
//make bullet clone and set it to whatever it’s on
var getLocation:Number;
var clone :Rigidbody;
clone = Instantiate(bullet, transform.position,transform.rotation);
//give the clone a velocity
clone.velocity = transform.TransformDirection(Vector3.forward*50);
//Get rid of the bullet by putting the bullet destroy script on the prefab
}
}
}
4). Drag the character controller into the empty variable slot.
5). Mess with the variables to get the AI to function how you want it. (You can now toggle yLock on and off to stop the enemy from chasing you up and down along the y axis).
EG: if you make the distance to activate big enough he will always follow you, turning canShoot to false will disable all shooting, and making move speed negative will make the AI run from you.
Stalker AI with Y Locked
This will make the enemy move on the X and Z axes
Make a script, paste this in.
Make sure everything in quotes is pink if it isn’t retype it and don’t forget the quotes!
then drag it onto the object you want to follow the player. Make sure you set target in the inspector to your Character Controller
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
var newPos = new Vector3(target.position.x, myTransform.position.y, target.position.z);
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(newPos - myTransform.position), rotationSpeed*Time.deltaTime);
//move towards the player
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}