So I added a code into my apc (exported from Maya) which translates the apc to positive z axis position giving the illusion that it is moving
#pragma strict
var speed : float = 5.0;
function Start () {
}
function Update () {
transform.Translate(Vector3(0,0,speed) * Time.deltaTime);
}
Now I want to add a JavaScript for enemy AI detection
so if player enters in range (specific range) of apc (either trigger or code) then health of player goes down by 10 kind of logic or I can jsut add a debug log for now to see if it’s working.
I want to break this step by step
I am new to js and I don’t know how or where to begin, are there any tutorials for this kind of AI logic?
If I created a cube on Unity then that cube would come with a box collider and trigger, but objects I export from Maya do not come with a collision box which means I have to create or apply a collision box to the apc myself, but how? Would it be through Components > Physics > Box Collider? and then would I need to parent it to the apc?
Or maybe I could create a new variable
something like
Var boundary : float = 100;
and if the apc gets to 100 then activate health or something
But how can I tell the program of the APcs exact position? So let’s say the apc starts off at a specific vector or position, can I say if player is <100 that position then trigger something for now I could add a debug.log to see if it’s working.
So if my character enters the sphere of the object that is moving then I get a message saying “apc has detected you” and the health which is 5 goes down to 4, note I debugged this via Log not actually a UI element yet but hopefully I’ll get there soon enough.
var health : float = 5.0;
function OnTriggerEnter (player : Collider) {
if(player.tag==“Player”)
health = health - 1;
Debug.Log(“apc has detected you” + health);
}
Now my next step is that the enemy detects me if I go into range but I want to add a code saying if my player is crouching then I will not be detected.
How can I do that?
I have a crouch script for my fp controller and in that script (which is in my fpcontroller) I made a new variable called “hidden”
The next question is how can I get variables from other scripts
because when I press c my player crouches and I made a variable, amde it 1 and I’m saying if player crouches then hidden (which is 1) = hidden + 1 which would equal 2
so now in my apc script I want to also say if hidden == 2 then…
this is my code for the apc character proximtiy detector
var health : float = 5.0;
function OnTriggerEnter (player : Collider) {
if(player.tag==“Player”)
health = health - 1;
Debug.Log(“apc has detected you” + health);
}
I’d just avoid the static for something like this and have hidden be a variable on your player stat script or whatever. then what ever needs to know the value of it would be something like this:
// this is code on whatever is checking the player's hidden value
var isPlayerHidden: int = 0; // base value not checked yet
//your code from above
function OnTriggerEnter (player : Collider) {
if(player.tag=="Player")
health = health - 1;
Debug.Log("apc has detected you" + health);
// basically says:
//set this var to the value of hidden in the script on the player object (you determinded above player=Player)
isPlayerHidden = player.GetComponent("NameOfPlayerScriptWithHiddenVariable").hidden;
}
also… my unityscript isn’t the greatest so sorry if there are any errors in syntax and such