Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Elisgamerz548 · Mar 27, 2019 at 01:44 AM · movement3dcollidersradius

basically i am having collider issues and idk wat to do

so essentially i have code to detect a collision and then if its tag is equal too a building then it goes to that building only problem being that some buildings have box colliders that i use for radiuses to collect resources and it seems whenever it detects this radius then it just ignores the soon collision with the actual building here is my code unsure of what is wrong with it thanks for the help!!!`

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.AI;
 public class Colliderai : MonoBehaviour
 {
     public float lookRadius = 10f;
     NavMeshAgent agent;
     public Transform target;
     public GameObject radiussawmill;
     public GameObject radiusquarry;
     public GameObject radiusoilrig;
     public void OnCollisionEnter(Collision collision)
     {
         print("touch");
         if (collision.gameObject.name == "prefabsawmill" )
         {
             target = collision.gameObject.transform;
             Target();
         }
         else
         {
             Physics.IgnoreCollision(radiussawmill.GetComponent<Collider>(), GetComponent<Collider>());
         }
     }
     private void Start()
     {
         agent = GetComponent<NavMeshAgent>();
     }
     void OnDrawGizmosSelected()
     {
         Gizmos.color = Color.red;
         Gizmos.DrawWireSphere(transform.position, lookRadius);
     }
     void Target ()
     {
         
         float distance = Vector3.Distance(target.position, transform.position);
 
                 if (distance <= lookRadius)
                 {
                         agent.SetDestination(target.position);
 
                     if (distance <= agent.stoppingDistance)
                     {
                         Vector3 direction = (target.position - transform.position).normalized;
                         Quaternion lookRotation = Quaternion.LookRotation(new Vector3(direction.x, 0, direction.z));
                         transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * 20f);
                     }
                 }
     }
 }`
 

Comment
Add comment · Show 7
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 Elisgamerz548 · Mar 27, 2019 at 01:46 AM 0
Share

for some odd reason my code snippet glitched a little sorry for the inconvenience! :3

avatar image Bonfire-Boy Elisgamerz548 · Mar 27, 2019 at 10:36 PM 0
Share

Fixed. Next time, try using the button with 101010 on it

avatar image Elisgamerz548 Bonfire-Boy · Mar 27, 2019 at 10:58 PM 0
Share

Can you assist me with this

Show more comments
avatar image Elisgamerz548 · Mar 27, 2019 at 06:29 PM 0
Share

Please help this is a crucial program

avatar image Taylor-Libonati · Mar 27, 2019 at 08:22 PM 0
Share

You can edit your post to fix the formatting. What is the purpose of Physics.IgnoreCollision? I am a little confused about what you want. You are checking if a collision occurs with prefabsawmill. And some of those objects have colliders that you don't actually want to collide with?

avatar image Elisgamerz548 Taylor-Libonati · Mar 27, 2019 at 09:23 PM 0
Share

That was one of my attempts to ignore the collision with the radius but otherwise I am trying to get it to ignore it but if there is another issue then please tell me

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Taylor-Libonati · Mar 28, 2019 at 12:40 AM

I think you need to move those colliders to a different transform. For example you could make a child on the building that is just for the resource collection collider and set its layer to something else. That way you know when you are colliding with the building in one way verse the other. I suggest looking at Unity Collision layers. With this you can have your ColliderAI not collide with anything but what its interested in: https://docs.unity3d.com/Manual/LayerBasedCollision.html

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

173 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Help with some collision mechanics and movement for my game. 0 Answers

My Character is unable to move since booting up Unity this morning, worked fine last night 0 Answers

Moving a 2D character along the X and Z axis only. 1 Answer

How to apply equal force back to player when colliding with a wall? 2 Answers

SteamVR - Collider marked as isTrigger won't pass the player through. 0 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