Home || Previous || Next

 

Using the code and animation from previous post

 

Making Sharkman react – the more moves the hungrier he gets.

 

Under the Movement script add line 32 where the engr. lowers each time you go to a waypoint.

Screen Shot 2015-11-26 at 14.24.43.png

Also edited the Shark Stats Script:

Screen Shot 2015-11-26 at 14.30.27.png

SharkMan is getting hungrier and angrier.

 

Editing the Patrol Function (Line 32)

Screen Shot 2015-11-26 at 14.32.17.png

Write a new Function called scan and run this in update.

Screen Shot 2015-11-26 at 14.42.12.png

Debug.DrawRay(GameObject.Find(“SharkmanFinal”).transform.position, transform.forward *6 , Color.red);

Screen Shot 2015-11-26 at 14.34.22.png

to easily edit the position of the shark man the code has been put into a Vector 3 and the x,y and z is added.Screen Shot 2015-11-26 at 14.44.37.png

Vector3 sharkmanPos = GameObject.Find(“SharkmanFinal”).transform.position;
Debug.DrawRay(new Vector3 (sharkmanPos.x, sharkmanPos.y +1, sharkmanPos.z), transform.forward * 6 , Color.red);

Shuffle the line so it is ontop of Sharkmans head. This line just shows us where the ray casting will be – will be edited out from final code when we have the recast in place

Screen Shot 2015-11-26 at 14.46.09.png

Create a Ray Cast object, want to come from same place as the red line – so copy past line.

Screen Shot 2015-11-26 at 14.50.10.png

if(Physics.Raycast(new Vector3(sharkmanPos.x, sharkmanPos.y +1, sharkmanPos.z), transform.forward *6, out forwardRay, 6)){}

What type of object is it detecting “Fish”

Screen Shot 2015-11-26 at 14.51.42.png

If we see our Fish and our 70% hungry the state is change to  hunt.

Screen Shot 2015-11-26 at 15.00.47.png

void Scan() {
Vector3 sharkmanPos = GameObject.Find(“SharkmanFinal”).transform.position;
Debug.DrawRay(new Vector3 (sharkmanPos.x, sharkmanPos.y +1, sharkmanPos.z), transform.forward * 6 , Color.red);
RaycastHit forwardRay;

if(Physics.Raycast(new Vector3(sharkmanPos.x, sharkmanPos.y +1, sharkmanPos.z), transform.forward *6, out forwardRay, 6)){
if(forwardRay.collider.tag == “Fish”){
if(GetComponent<SharkStats>().hunger >= 70){
GetComponent<StateMachine>().state = “HUNT”;
}
}
}

}

 

Home || Previous || Next

 

 

 

Advertisements