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 SantiMuffin · Aug 01, 2012 at 05:58 PM · c#charactercontrollercollision detectionnewbie

Finding an object is within an another

Hi all,

This is my first post on the forums and I'm still pretty new to Unity so i have a small issue. I have a main script that governs how objects move within the screen. It uses a character controller to accomplish this. Then in an inherited class i specify how the move is set. On the player i grab the input like oh so many tutorials and on any enemy that moves i try to find if a player is within a certain range, if he is i look at him and create a vector towards him.

 if(isActive)
  {
  transform.parent.LookAt(new Vector3(
  trPlayer.position.x, 
  transform.parent.position.y,
  trPlayer.position.z));
  moveParse = trPlayer.position - transform.position;
  parentMove.move = moveParse.normalized;
  }
  else
  parentMove.move = new Vector3(0.0f, 0.0f,0.0f);

The enemy has a child which is a sphere when the player enters this sphere it functions as a trigger and it communicates to the enemy where the player is within this Field of View.

This works pretty good most of the time. The big problem starts when i duplicate the enemy, since they will begin climbing in-top of each other. I have tried to find many ways of fixing this issue but im starting to think my approach is flawed.

I read somewhere that a similar way of doing this is by using ray cast but i believe this would be more expensive (process wise) since each ray must be checked for collisions and instantiated.

So how would i go about stopping the objects from climbing each other?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by strachpr01 · Aug 01, 2012 at 08:03 PM

could you try adding an extra boolean so if another enemy enters its sphere to stop moving until it is gone therefore they would not be able to 'climb' over one another.

Comment
Add comment · 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
0

Answer by SantiMuffin · Aug 01, 2012 at 10:20 PM

the problem is that i need them close enough as to actually stop the player from being able to advance. But maybe adding another sphere collider that is the size of the enemy will allow me to implement this. How expensive can a solution like this be when it comes to resources? Wont it be checking for more collision?. (Thinking that this will be for a mobile device).

Comment
Add comment · Show 2 · 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 strachpr01 · Aug 02, 2012 at 05:37 PM 0
Share

When you say you wish for the player not to be able to proceed. Are the enemies constantly moving towards the player or are they moving into a set position to block the player at a bottleneck in the game?

avatar image SantiMuffin · Aug 02, 2012 at 05:58 PM 0
Share

Right now they are constantly moving towards the player so as to block his path. Since the player will always come from the -z direction the idea is for them to try to block his path or go towards him to kill him.

avatar image
0

Answer by SantiMuffin · Aug 08, 2012 at 11:16 PM

Just to close the matter I went with making a cube that is 10% bigger than my item and using it as a Trigger. :)

Comment
Add comment · 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

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

7 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Resize Array Based on Value 2 Answers

how to make my character go round loops? 1 Answer

Unity can't find Character Motor and max forwad speed -1 Answers


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