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 neoshaman · Jun 17, 2013 at 11:59 AM · collisioncharactercollision.contacts

Custom collision detection

I'm trying to make a custom collision detection to get rid of the physics of unity but it doesn't work, it doesn't detect collisions correctly. I'm using sweeptest and sweeptestAll to listen collision around a sphere to a mesh (scene). The goal is to make a character that move along the tangent of the collided surface. However it fails critically at inward curve and at wall obstacle! Typical rigidboy non kinetic collision slow the computer down to a slide show, that is the reason for the custom code (intel atom n455).

What should I do to fix my solution? is there other solution to try?

Here is the current code:

 private void UpdateSurfacePosition()
     {  
         Ray//origine, direction
             ground_check_ray = new Ray( gameObject.transform.position, -gameObject.transform.up);// * (Momentum.magnitude + 1));
         RaycastHit
             raycast_result;
         Rigidbody
             rigid_body = gameObject.rigidbody;
  
  
         rigid_body.detectCollisions = false;
         rigid_body.isKinematic = true;
  
  
  
         bool onGround;// =
             //Physics.Raycast( ground_check_ray, out raycast_result );//ray, hit
             //rigid_body.SweepTest(-gameObject.transform.up, out raycast_result);//direction, hit, distance
  
         raycast_result = new RaycastHit();
         RaycastHit[] contacts = rigid_body.SweepTestAll(-gameObject.transform.up);
  
         rigid_body.SweepTest(-gameObject.transform.up, out raycast_result);
  
  
         if (contacts.Length > 0)
         {
             onGround = true;
             int i=0; while (i != contacts.Length)
             {
                 raycast_result.normal += contacts[i].normal;
                 i++;
             }
             raycast_result.normal = raycast_result.normal.normalized;
         }
         else
         {
             onGround = false;
         }
  
  
         debug1 = "Normal > " + raycast_result.normal.ToString()
             + " Position > "+ raycast_result.point.ToString()
                 //+" transform > "+ raycast_result.transform.name.ToString()
                 + " Contact > " + contacts.Length
                 ;
  
  
         if ( onGround )
         {
             Vector3
                 next_position;
  
             //UpdateOrientation( gameObject.transform.forward, raycast_result.normal );
  
             UpdateMoveOrientation( gameObject.transform.forward, raycast_result.normal );  
             next_position = GetNextPosition( raycast_result.point );
             rigid_body.MovePosition( next_position );
  
  
             //ground_direction = raycast_result.normal;
         }
         else//onAir
         {
             //if forward close to dot.Y = abs(1) choose -up if 1 and up if -1
             UpdateMoveOrientation( gameObject.transform.forward, raycast_result.normal );
         }
     }
Comment
Add comment · Show 6
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 neoshaman · Jun 24, 2013 at 03:04 AM 0
Share

http://forum.unity3d.com/threads/142375-The-limitations-of-the-physics-API-and-creating-a-character-controller

O$$anonymous$$AY it's just that unity can't make any kind of complex gameplay at all, he confuse physics for collision, I just need a good system to resolve collision not to rewrite physX from scratch. No wonder any sane dev avoid unity for AAA. It's cute for some simple game, nothing serious or too complex. I'm glad I haven't bought the expensive useless license ...

avatar image whydoidoit · Jun 24, 2013 at 04:22 AM 0
Share

You do know that PhysX is Nvidia right and not Unity? If you are building an FPS which for some reason needs very accurate collision detection then yep, PhysX is crap with mesh based colliders due to back face culling and the need for convex meshes if they are to collide with each other.

avatar image neoshaman · Jun 24, 2013 at 03:54 PM 0
Share

Well unity choose what they add in their package, it is sold as a kind of ultimate game dev package and yet failed at most basics level. It make sense commercially as it port to multiple platform, but creatively it's a mess.

I'm not trying crazy hard stuff here, 1 single Sphere to scene $$anonymous$$esh is like basic requirement, except: 1 - I'm on a low end machine, not only rigid bodies is crazy expensive but it came with physics stuff I don't need and which fucked up the collision resolution. I have just one scene and one object and it's a slide show! 2 - It fails at a convenience because collision resolution tools are weak and don't provide enough data and have many quirks to find out. You can't even properly write your own collision resolution using primitive tools. 3 - It fails for game because the most important things is collision detection and automatic resolution (not going through wall and object) which unity fail to provide without extra code, and the unnecessary expensive physics is not typical gameplay case. Research show that's the most common problem people have with unity, so it's not an isolate accident. $$anonymous$$ost complain goes to how rigidbody act weird, is expensive and how the character controller is shit. That's like the basic of most actions games! It's sold as a game engine, proper collision handling in the context of game is a very basic requirement!

But it lead to a larger problem with so called collision engine, most coder feel the urge to do a full physics engine that user are quick to try neutralizing. I have yet to see a collision engine that is design for typical gameplay and have things like moving platform just work without extra code. Blitz3D is the closest to my knowledge, it has collision, layer, no physics and handle automatically resolution to prevent overlap, and send you all the data you need like contacts and normal for you to decide gameplay. It does not handle moving platform automatically but that's as close as possible to video games oriented collision engine. Too bad its renderer is obsolete in most modern card.

Now $$anonymous$$aybe there is alternative to unity, Do you know some?

avatar image Loius · Jun 24, 2013 at 05:53 PM 0
Share

Walking the perimeter of a concave 3D shape is one of the most complex things you can do with physics. Casting in only the character-down direction is unlikely to solve the problem.

Raycast works. Sweeptest works. They do what they say they do, you just need to tell them to do the right thing. Unity has collision layers, physics contact information (from Raycasts and from OnCollision triggers), things don't go through each other unless they're physics-ally impractical objects to begin with (where the problem would appear regardless of engine, and that can be fixed easily on a per-case basis).

Here is a similar question, with a possible solution - Link

avatar image neoshaman · Jun 25, 2013 at 01:03 AM 0
Share

I made of a rant for sure, I have been working on this simple thing for 3 years, fighting gimbal lock, quaternion and finally hairy ball ...

In fact I solved the wall hugging problem with a sphere collider with rigidbody at the expense of performance (slide show fps) then try to replicate with casting but I don't have enough precision.

BUT I tried to reuse the same rigidbody back into the code ... and it break, it does not work anymore ...

https://dl.dropboxusercontent.com/u/24530447/flash%20build/litesonicengine/LiteSonicEngine8.html New code with solved control but broken collisions, much simpler strip down code to focus on the main problem of control.

https://dl.dropboxusercontent.com/u/24530447/flash%20build/flash%20sonic/flash%20sonic.html This version has much more advance version but suffer from gimbal locks problems (arrow and mice to control, jump with lmb, try to go inside the tube). In this version collision is really solid, wall hugging works well but have directional discri$$anonymous$$ation for ceiling and wall direction.

If I solved this correctly, and integrate everything in once package, I'll released the controller for everyone with extra goodies (most notably input lock to reverse intelligently control on ceiling, ie when the user is no more holding the move button).

Show more comments

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

16 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

Related Questions

Character mouvement and collisions in arbitrary angled surface 1 Answer

collision detection not working? 1 Answer

Since unity is not recommending using collision.contact as it produces memory garbage how should I then get the point of collision? 1 Answer

My character jumps occationally when against a wall? 2 Answers

I just made my animation loop, but now my character walks through all colliders? 2 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