- Home /
Enemy character controller
happy new years unity community quick question i looked around first and did not find any info on this so i thought to ask here im trying to put a creature in my game with six legs and a spider like body its the free cave worm on the asset store i have it going and set up with AI but i ran into an issue the character controller collision capsule doesn't fit I changed the radius and heights to fit good but its either too big so if i shoot the air next to it it will hit the enemy or too small and i cant hit most of the body parts so has anyone come across a better way to do a better character controller if i could add more then one capsule i would be able to do it but i cant or don't know how anyone have any ideas I would be very appreciative.
UPDATE :
I have been playing around with it and i put colliders in the bones of the model so i can shoot each spot but i cant seem to figure out how to send the damage to my main body so i can kill it ive tried this
using UnityEngine;
using System.Collections;
public class BodyPartdamage : MonoBehaviour {
void Start () {
if(other.GetComponent<CharacterDamage>() != null){
other.GetComponent<CharacterDamage>().hitPoints -= damage;
}
}
void Update () {
}
}
something i tested out but doesn't work im trying to get it to just send the damage to my main body when i shoot
Update : ive tried and failed again there has to be a simple way to do this this is what i tried this time but i cant figure out how to send the send the float damage with the message
using UnityEngine;
using System.Collections;
public class BodyPartdamage : MonoBehaviour {
public GameObject parent;
// Use this for initialization
void Start () {
}
public void ApplyDamage ( float damage, Vector3 attackDir, Vector3 attackerPos ){
if (parent != null)
{
parent.SendMessage("ApplyDamage");
}
}
}
Update :
I tried this too .... i think i got closer but its giving me this error error CS1501: No overload for method ApplyDamage' takes
1' arguments.... i feel a little stupid at this point all i want is when my bullet hits the collider that is part of the bones to send rerout the message to my NPC's Damage handler
using UnityEngine;
using System.Collections;
public class BodyPartdamage : MonoBehaviour {
public GameObject parent;
// Use this for initialization
void Start () {
}
public void ApplyDamage ( float damage, Vector3 attackDir, Vector3 attackerPos ){
if (parent != null)
{
parent.GetComponent<CharacterDamage>().ApplyDamage(damage);
}
}
}
this is what the weapon does when it hits an NPC layer
if(hit.collider.gameObject.GetComponent()){ hit.collider.gameObject.GetComponent().ApplyDamage(damage, direction, mainCamTransform.position);
but the collider im hitting doesent have the characterdamage script so i need it to reroute it to the game object that does using
public GameObject anyname;
to specified game object with the characterdamage script because it is the parent game object sorry for so much but im lost im not a good programmer (learning) so i realy cant see what im doing wrong
Answer by Kyieon · Jan 02, 2014 at 11:39 PM
Try something like this. Its just pseudocode so you might need to adjust it.
public void ApplyDamage(float bulletDmg, string bodyPartName){
if(parent != null){
if(bodyPartName == "leg"){
float bodyPartMultiplyer = 0.25f;
parent.GetComponent<CharacterDamage>().hitPoints -= (bulletDamage * bodyPartMultiplyer);
}
}else if...
}
ok thank you so much trying it right now had to take a break lol
no dice messed with it for about an hour i put it in and made it work with the scripts and it partially worked the enemy was hurting its self... and my bullet did nothing i changed the name of the public void to something else so the enemy wouldn't hit itself but it still hit itself and i added its own little function in my weapon script and it still doesn't work im so stumped..
this is what i ended up with from that i removed some stuff
using UnityEngine;
using System.Collections;
public class BodyPartdamage : $$anonymous$$onoBehaviour {
public GameObject parent;
public float DamageAmplifier = 0.25f;
// Use this for initialization
void Start () {
}
public void HitBodyPart(float damage){
if(parent != null){
float bodyPart$$anonymous$$ultiplyer = DamageAmplifier;
parent.GetComponent<CharacterDamage>().hitPoints -= (damage * bodyPart$$anonymous$$ultiplyer);
}
}
}
AND
this is the change i made to rthe weapon script
if(hit.collider.gameObject.GetComponent<BodyPartdamage>()){
hit.collider.gameObject.GetComponent<BodyPartdamage>().HitBodyPart(damage);
}
had to do that because the enemy can also attack other npc and it was attacking itself but even with the change it still damages itself im sure i have to look into if there are tags set but i should be hitting it too if you would like to see the full script i cant post it here but i will be happy to share privately if you cant see the issue in these codes thank you again
Take the "HitBodyPart" function out of the start function :)
just tried it dident work either but the multiplier works now :)
Your answer
Follow this Question
Related Questions
Character Controller not ground object 1 Answer
Colliders doesn t collide with CharacterController 1 Answer
CharacterController collision disabled when modifying center 0 Answers
Rigidbody: how to get collisions for the current frame ? 0 Answers
How do I go about adding basic pathfinding to my enemy? 1 Answer