Problems with enemies (37120)

Hey guys i need help. I am making a game where a robot chases the player(you) and tries to kill it and you kill them like a zombie game. So here is the problem the robot in unity are not realy solid. They can walk on the floor but they go through walls, when they walk helf of there body is in the ground, and somehow they can fly when i am on a object. If you can help me with any of these problems that would be great. Thanks

Well theres one problem

6 Answers

6

hey skully42, seems like a few people are berating you on here. to answer your what do you want me to do. refine your question… what have you tried? have you coded any scripts? if so what are the scripts? are you attempting to use collision? was the enemy made in a software application such as 3ds max or maya? if so did you put a mesh collider on it?

these things help us help you. telling us everything you’ve done will help us find a quick solution to your issue.

from what i have read it sounds like you have a enemy that has no rigid body or box collider on it so it doesn’t do any collision detection.

Well, then you can just move the enemies y position up above the floor, so it doesn't fall through.

ok, so copy and paste the 'chase' code underneath this comment.

Maybe stick to just asking the question once and revisiting it? Plenty of people have offered advice already, maybe you should look more into that before asking again and again?

Ok, not to fear there skully. And don’t worry about the format its fine.

Attach this script to your robots:

chase.js:

var target : Transform; 
var moveSpeed = 3; 
var rotationSpeed = 3; 
var myTransform : Transform; 

function Awake () {

    myTransform = transform; 

}

function Start () {

     target = GameObject.FindWithTag("Player").transform; 

}

function Update () {

    myTransform.rotation = Quaternion.Slerp(myTransform.rotation,

    Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);

    myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;

}

If I got something wrong or you received an error tell me cause I haven't tested it.

So they still fell through the floor?

Try putting a box collider on your floor.

:slight_smile: did you adjust the character collider ? - on default it is usually not set to fit your character.
Click on your Enemy in the hierachy - and look up its character collider - set the y value a bit higher… and make sure most of your character is surrounded.
That should stop your enemies from walking through the floor and foor the rest… idk :slight_smile:

Cheers Kerg.

just adjust your enemies CharacterController. it is that green wireframe thing - it defines the whether your characters sink into ground or not.
Click your enemy - look up the CharacterController adjust the y value (usually put in a higher number) push play - see if its alright - if not … play with the numbers a bit. Should do the trick.
or even better :wink: write a script to do it for you :wink:
something like…
http://unity3d.com/support/documentation/ScriptReference/CharacterController-height.html
instead of hardcoding you could use a public variable → then you can play with the value in the inspector.
and maybe you want to look up
http://unity3d.com/support/documentation/ScriptReference/CharacterController-radius.html → define the radius
http://unity3d.com/support/documentation/ScriptReference/CharacterController-center.html → my personal favorite. creates a dependency between the transform and the controller.

I hope 90 % of what I wrote is alright. I am a newbie as well :wink:

Cheers
Kergal

This link fixed an identical problem for me, in your enemies following script place it right under the “function Update(){”, it might solve it for you