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 /
  • Help Room /
avatar image
0
Question by V01D_2 · Jul 22, 2020 at 03:28 PM · rigidbodycollision detectionrigidbody-collisioncollision issuescollision event

Evading obstacles

I am working on a game in which the character (a bird like creature) will automatically evade obstacles. For example, instead of letting one wing go through the wall, the bird will rotate by 90 degrees to evade it. I am using a rigidbody controller, and a box collider on the wing. The obstacle has a box collider as well, and both colliders have isTrigger enabled. This works, kind of... If the left wing evades the obstacle, I can A. move through the obstacle (no matter what, since both are trigger) and B. when I move to the right (further away from the obstacle) the character will start jittering like crazy. I suspect this to be because the collider will no detect anything, thus moving back to it's original rotation (0 degrees) but it rotates back once it collides.

My questions here are:

  1. How can I fix the issue with a more smooth collision?
  2. How can I prevent the player from moving through the obstacle? (Adding a second box collider with isTrigger set to false, will make the rotation really harsh, and not smooth since I collide with the box too.

Here is my code:

 using JetBrains.Annotations;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 /*
 Autoevasion will smooth out the collision either of the wings detect. By rotating as if the player turned left or right. 
 */
 
 public class autoEvasionLeft : MonoBehaviour
 {
     public GameObject orbit; //bird creature (player)
     public bool mustMoveL = false;
 
     private Vector3 currentPosition;
     private Vector3 safeDistancePositionVector;
     private Vector3 velocity = Vector3.zero;
     private float smoothRotationTime = 5.0f;
     private Rigidbody rb;
 
 
     private void Start()
     {
         rb = orbit.GetComponent<Rigidbody>();
     }
     
 //This will shoot the character away, which is NOT what I want.
     private void OnTriggerEnter(Collider other)
     {
         //Move away from object
         //currentPosition = orbit.transform.position;
         //safeDistancePositionVector = new Vector3(currentPosition.x + 2, currentPosition.y, currentPosition.z);
         //orbit.transform.position = Vector3.SmoothDamp(currentPosition, safeDistancePositionVector, ref velocity, Time.deltaTime * smoothRotationTime);
     }
 
     private void OnTriggerStay(Collider other)
     {
         //Found jitter bug on contanct. The reason for this is that the colliders moves away, and comes in contanct again thus going back and forth
 
         if (other.tag == "noZone") //noZone defines the non reachable areas by the player, i.e. gameobjects colliders collide against
         {
             //Rotate to evade the object
             Quaternion rotationalTargetAngle = Quaternion.Euler(-209.93f, -90, 89.99999f);
             orbit.transform.rotation = Quaternion.Slerp(orbit.transform.rotation, rotationalTargetAngle, Time.deltaTime * smoothRotationTime);
         }
     }
 }

I have some ideas, but they are really weird to implement.

  1. Once I rotate, disable controls for  moving left and right (bad gameplay experience)
  2. Once I rotate, shoot a raycast from the back of the bird, and if the raycast detects nothing, the object is gone.
  3. Get collider.transform and set an offest, then move the player to that offset.

Is there someone who has a better implementation or a suggestion on which Idea would be fastest, easiest, and best in player experience?

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

0 Replies

· Add your reply
  • Sort: 

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

255 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 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

RigidBody Collision Detection Error 1 Answer

Collisions and ejection without physics etc. 0 Answers

Player with collider goes through another object's collider upon first collision, works only on second time 0 Answers

How can I detect collision between two objects when one can't have a rigidbody applied? 1 Answer

Trigger Object is still moving objects? 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