Jump to content

Hey guys, I'm creating a game on unity for a school project and would like some help. I have a bit of a strange setup but it works kind of, I have a 2D game setup with 3D physics. The reason for this is because one of my scripts which disables the player from infinitly jumping only works when all the object are set up with 3D box colliders ( I will include that script as well if any of you know how to fix that). The problem I have with the AI, is that there is a hit box i have setup ontop of the AI which will be used to kill it like goomba from mario, however the AI keeps rotating as it follows my player making it impossible for the player to kill it ( That being said the killing/destroying part of the script hasn't been implemented yet as I have to fix this crippling bug first.)

 

PS: I am using javascript 

 

The Jumping Script

var power : float = 100;
var Floor : String;
var Platform : String;
var isGrounded : boolean = true;
 
function Start () {
 
}
 
function OnCollisionEnter(theCollision : Collision){
 
if (theCollision.gameObject.name == Floor||Platform){
 
isGrounded = true;
// Debug.Log("Jump Enabled");
 
}
}
 
function OnCollisionExit(theCollision : Collision){
 
if (theCollision.gameObject.name == Floor||Platform){
 
isGrounded = false;
// Debug.Log("Jump Disabled");
}
}
 
function Update () {
 
if(isGrounded == true)
{
 
if(Input.GetKeyDown(KeyCode.UpArrow))
{
rigidbody.AddForce(Vector3(0,power,0));
// Debug.Log("Jump");
}
}
 
}
 

 

AI script

 

var Target : Transform;var moveSpeed : int = 5;var chaseDistance : int = 20;function Update () {	Distance = Vector3.Distance(Target.position, transform.position);		if(Distance < chaseDistance)	{		transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);//		transform.Translate(Vector3.MoveTowards(Target) * Time.deltaTime);			}		}

 

Thanks

My Current Rig: CPU: i7 4790k @ 4.8Ghz CPU Cooler: H100i MOBO: Gigabyte Z97X SOC GPU: XFX Radeon HD 7950 Tahiti pro (Died 6/07/2014 RIP) & PowerColour HD7950  GPU Cooler: NZXT G10 W/ Corsair H55 HDD&SSD: Seagate Barracuda 1TB + Corsair GS 128GB + Samsung 840 EVO 250GB PSU: Corsair RM 750 Case: Fractal Design Arc Midi R2.  


 

Link to comment
https://linustechtips.com/topic/195621-unity-ai-help/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×