Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by wadawalnut · Dec 20, 2012 at 02:17 AM · colliderfpswallwtf

AI GameObjects Go Through Walls?

Hello, I am making a game where tigers spawn and chase after you. I set up a scene where you are in a hotel-like place, all the walls are made out of unity cubes and therefore have box colliders set automatically. The tigers have rigidbodys and box colliders of their own. They contain this script to chase after the player: var target : Transform;

 var moveSpeed = 20; 
 
 var defMoveSpeed;
 
 var rotationSpeed = 3; 
 
 static var reflex : boolean = false;
 
 var myTransform : Transform; 
 
 var runningIntoWall : boolean = false;
 
 
 
 function Awake()
 
 {
 
     myTransform = transform; 
 
     if (reflex){
 
         moveSpeed *= 3;
 
         rotationSpeed *= 3;
 
         defMoveSpeed = moveSpeed;
 
     }
 
     if (!runningIntoWall){
 
         defMoveSpeed = moveSpeed;
 
     }
 
 }
 
 
 
 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;
 
     moveSpeed = defMoveSpeed;
 
 }
 
 
 
 function OnCollisionEnter(theCollision : Collision){
 
     if (theCollision.gameObject.name == "Wall" || theCollision.gameObject.name == "2_Wall" || theCollision.gameObject.name == "3_Wall" || theCollision.gameObject.name == "4_Wall" || theCollision.gameObject.name == "2_Door" || theCollision.gameObject.name == "3_Door" || theCollision.gameObject.name == "4_Door" || theCollision.gameObject.name == "2_Room" || theCollision.gameObject.name == "3_Room" || theCollision.gameObject.name == "4_Room"){
 
         moveSpeed = 0;
 
         runningIntoWall = true;
 
     }else {
 
         moveSpeed = defMoveSpeed;
 
         runningIntoWall = false;
 
     }
 
 }

However, often the tigers manage to break through the walls! Does anyone know how to fix this? Thanks!!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by clunk47 · Dec 20, 2012 at 02:52 AM

Set your tiger's rigidbody Collision Detection mode to Continous Dynamic in the inspector, or via script like so:

 rigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;

This is so that fast moving objects will ALWAYS check for collisions, unlike the "Discrete" option.

If this doesn't help, you could also give the walls a Rigidbody component and set their collision detection mode to Contiuous (Not Dynamic). You would need to constrain the walls so they can't be moved, but you DO NOT want to do this by setting them as Kinematic. There is a constraints option in the inspector, lock rotation and movement on all axes, or do this via script like so:

 rigidbody.constraints = RigidbodyConstraints.FreezeAll;

Another approach I can think of, instead of moving the tigers with transform.position, try using rigidbody.velocity in the same manner like:

     rigidbody.velocity = transform.forward * moveSpeed * Time.deltaTime;
 

This should help, if not I can brainstorm some more :)

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image wadawalnut · Dec 20, 2012 at 03:12 AM 2
Share

Thanks so much for your response! I think the last tip worked (the one with rigidbody velocity ins$$anonymous$$d of transform position) except the tiger didn't move. So I use rigidbody velocity and transform position to locomote the tiger and it works! Thanks a lot!!!

avatar image clunk47 · Dec 20, 2012 at 03:14 AM 2
Share

Happy I could help! I voted up your question for it being a good one :) If this seems to be a resolution for your issue, I would be greatly appreciative if you could Vote up (thumbs up icon) and Accept the answer (Check$$anonymous$$ark). Have a great day! :D

avatar image clunk47 · Dec 20, 2012 at 03:18 AM 1
Share

Well you don't have to accept the answer if it doesn't completely resolve the problem :) That way people will know you still need help, sorry I was unable to resolve.

avatar image clunk47 · Dec 20, 2012 at 03:19 AM 1
Share

Try the velocity method again, and turn UP the movespeed, see if that helps. If not, use some Constant Force. Then in script use constantForce.force = transform.forward moveSpeed Time.deltaTime;

avatar image clunk47 · Dec 20, 2012 at 03:20 AM 1
Share

constantForce.force is a Vector3 so it won't be too hard to experiment w/ :)

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Gun goes through wall in a FPS 5 Answers

Collision Problem with Rigidbody? 1 Answer

OnTrigger Box Collider Doesn't Work? 1 Answer

A node in a childnode? 1 Answer

Object Collider problem, objects going through walls? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges