Question by
AWilliams5 · Mar 12, 2019 at 03:29 PM ·
c#animatoraicontrollerfightingame
How to program an AI fighting game code? And how to fix this problem with my Code?
Hi, starting with the second question. I'm having an issue where Unity gives me this warning that says (animator is not playing an animatorcontroller) Here is the Code I used for my Player_Controller
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Fighter_Player : MonoBehaviour {
public enum PlayerType
{
HUMAN, AI
}
public static float MAX_HEALTH = 100F;
public float healt = MAX_HEALTH;
public string fighterName;
public Fighter_Player oponent;
public PlayerType player;
protected Animator Player;
private Rigidbody myBody;
// Use this for initialization
void Start () {
myBody = GetComponent<Rigidbody> ();
Player = GetComponent<Animator> ();
}
public void UpdateHumanInput () {
if (Input.GetAxis ("Horizontal") > 0.1) {
Player.SetBool ("Walk_Forward", true);
} else {
Player.SetBool ("Walk_Forward", false);
}
if (Input.GetAxis ("Horizontal") < -0.1) {
Player.SetBool ("Walk_Backward", true);
} else {
Player.SetBool ("Walk_Backward", false);
}
if (Input.GetAxis ("Vertical") < -0.1) {
Player.SetBool ("Duck", true);
} else {
Player.SetBool ("Duck", false);
}
if (Input.GetKeyDown (KeyCode.F)) {
Player.SetTrigger ("Punch_Mid");
}
if (Input.GetKeyDown (KeyCode.G)) {
Player.SetTrigger ("Special_Move");
}
}
// Update is called once per frame
void Update () {
Player.SetFloat ("health", healtPercent);
if (oponent != null) {
Player.SetFloat ("oponent_health", oponent.healtPercent);
} else {
Player.SetFloat ("oponent_health", 1);
}
if (player == PlayerType.HUMAN) {
UpdateHumanInput ();
}
}
public float healtPercent {
get {
return healt / MAX_HEALTH;
}
}
public Rigidbody body {
get {
return this.myBody;
}
}
}
I also would like to know how to program an AI fighter. I have been following this guy for my code and AI https://www.youtube.com/watch?v=IR437gsoG-M∈dex=20&list=PLO8VSSi-HMWTpBk7WIEL_iVfyQLebqtiJ
but when I type in the code for the AI, the controller stopped working and all I could do was walk forward and eventually got to the point where I couldn't move at all.
Comment