- Home /
Boxing character and AI enemys
I have a third person (based on TornadoTwins tutorial) that can walk, rotate and shoot fire balls. On one point in my game he lossing hes ability to shoot so he have to use he's hands to fight, like boxing. how do I animate him that it will look like he hits the enemys (3 hits) and the enemys will seems like they being hit by me?
here is my character script:
//Walking
var speed = 20.0;
var rotateSpeed = 4.0;
//Shooting var bullitPrefab:Transform;
//Dying private var dead = false;
//Getting hit var tumbleSpeed = 800; var decreaseTime = 0.01; var decayTime = 0.01; static var gotHit = false; private var backup = [tumbleSpeed, decreaseTime, decayTime];
function LateUpdate() { if (gotHit) { if(tumbleSpeed < 1) { //we're not hit anymore... reset & get back in the game! tumbleSpeed = backup[0]; decreaseTime = backup[1]; decayTime = backup[2]; gotHit = false; } else { //we're hit! Spin our character around transform.Rotate(0, tumbleSpeed * Time.deltaTime, 0, Space.World); tumbleSpeed = tumbleSpeed-decreaseTime; decreaseTime += decayTime; } } }
//function OnControllerColliderHit(hit : ControllerColliderHit) function OnTriggerEnter( hit : Collider ) { if(hit.gameObject.tag == "enemyProjectile") { dead = true; //substract life here HealthControl.LIVES -= 1; gotHit = true; Destroy(hit.gameObject); }
if(hit.gameObject.tag == "HP_Capsule") //extra Lives
{
if(HealthControl.LIVES >=3)
{
HealthControl.LIVES +=1;
Destroy(hit.gameObject);
}
else
{
HealthControl.LIVES = 3;
Destroy(hit.gameObject);
}
}
}
function Update () { var controller : CharacterController = GetComponent(CharacterController); transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
//Shooting!
if(Input.GetButtonDown("Jump"))
{
var bullit = Instantiate(bullitPrefab, transform.Find("SpawnPointB1").transform.position, Quaternion.identity);
bullit.tag = "bobProjectile";
bullit.rigidbody.AddForce(transform.forward * 5000);
}
}
@script RequireComponent(CharacterController)
Another question i have is how to make the enemys follow after me and rotate? how to make an AI enemy?
Answer by FLASHDENMARK · Feb 10, 2011 at 02:11 PM
var distance; var target : Transform; var lookAtDistance = 15.0; var attackRange = 10.0; var moveSpeed = 5.0; var damping = 6.0; private var isItAttacking = false;
function Update ()
{
distance = Vector3.Distance(target.position, transform.position);
if(distance < lookAtDistance)
{
isItAttacking = false;
renderer.material.color = Color.yellow;
lookAt ();
}
if(distance > lookAtDistance)
{
renderer.material.color = Color.green;
}
if(distance < attackRange)
{
attack ();
}
if(isItAttacking)
{
renderer.material.color = Color.red;
}
}
function lookAt () { var rotation = Quaternion.LookRotation(target.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping); }
function attack () { isItAttacking = true; renderer.material.color = Color.red;
transform.Translate(Vector3.forward * moveSpeed *Time.deltaTime);
}
Here is a VERY basic AI. Just remember to drag the target you want the AI to follow in the inspector. When you come in a certan range it will look at you. If you get even closer it will attack you. I dont know if you can use this or not.
Tell me if there is something you wanna know and if you can use this.
Happy to help :)
thx. (wow, that answer was fast...).I'll try it. I asked about the animate of the "Boxing Charecter", can you help me with that?
THAT-AWSO$$anonymous$$E!!! That AI works great! thx so much!
That is great! :) I am afraid that i can not help you further, since that is not so much my thing :(. Sorry, but good luck with your project ;)
This is really cool. Who is the man? You are. THAN$$anonymous$$ YOU :)
Answer by anamzara · Jan 16, 2018 at 02:26 PM
thx. (wow, that answer was fast...).I'll try it. I asked about the animate of the "Boxing Charecter", can you help me with that? max muay thai thai tube baiyoke sky buffet Tokyo sky tree universal studios singapore Australia zoo
Your answer
Follow this Question
Related Questions
Character Animation won't work with FPS scripts 1 Answer
Simple AI and Animation 2 Answers
How to handle multiple animation variants 1 Answer
Camera shall stay on face while animating a Character 0 Answers
Character Pipeline 1 Answer