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 /
  • Help Room /
avatar image
0
Question by simunovic100 · Feb 17, 2017 at 06:29 AM · collisionrigidbodymousedrag

Stop a rigidbody on collide when dragging it with a mouse / with DontGoThroughThings

Hi,

I'm making a game where you drag sphere game objects across 3 dimensions by snapping to fixed y or z screen values when pressing the "H" key (fixed z - moving the object up when moving the mouse forward/ fixed y - object going further from the camera by moving the mouse forward). The objects x axis on drag is always represented with a left-right mouse movement and it's original position.

I'm setting the object position with transform.position but i can change it to rigidbody.moveposition if it would help me resolve this in a good way, but i would rather not as it screws up other things in the game.

Since I'm moving my object with a mouse and those mouse movements can be fast, I'm sometimes skipping the collision. I've searched the web and most of the successfully solved topics regarding this issue are answered with the DontGoThroughThings Script. After adding the script to my objects they would follow your mouse and in the same time trying to keep the position which the Don'tGoThroughThings is giving it, creating a blinking/glitch effect. This is on high speed collision detected by the script.

I wanted to make this object wait for me to come back for it with the mouse on the collision point that the DGTT script passes him, so I've added a public bool to the DGTT script and set it to false when there's a collision in the DGTT and then not do the transform.position from the drag...And set it to true when mouse leaves object, then doing the drag transform.pos... This works pretty well, besides a few occasional glitches on high speed collisions (Who's cause I can't track down) AND the low speed collisions causing the object to bounce right off (I can target the ball after the bounce while still holding mouse button and gain control of the object again, all in the same click, similar like I do when the object is waiting on the collision spot for the mouse on high speed collisions). The bounce is happening due to the normal collision being detected...

So my bottom line question is: How do I get to control the behavior of the drag collision so that I have balls ALWAYS bounce off a wall type 1 (No matter if the collision is high or low speed, in other words DGTT collision or Standard physics that take place), also to have the balls always wait for the mouse on the collision point with walls type 2, and finally to have the balls stop and drop on collision with walls type 3(I think i got these last two covered but I would like to hear your opinion).

How do I get to control the behavior of the drag collision so that I have balls ALWAYS bounce off a wall type 1. This leaves me without an idea and I'm quite stuck, I can't think of a way how to keep those two different bounces the same in the borderline cases (First High Speed and Last Low Speed bounce)... As i see it i would keep the normal physics bounce and do a addforce for the high speed one after I position it in the collision spot, right? But how......Wait a second...I got something with that... It's really great to put your issue "down on paper", as I discovered many things while trying to formulate the question... I got this Always Bounce behavior to work with this two extra ifs in the top of the DGTT if raycast (executing before standard three cases in the DGTT script):

 if (doThisShit2) //execute bounce
                     {
                         myRigidbody.useGravity = true;
                         myRigidbody.position = hitInfo.point - (movementThisStep / movementMagnitude) * partialExtent;
                         myRigidbody.AddForce(- 100 * (hitInfo.point - (movementThisStep / movementMagnitude) * partialExtent));
                         doThisShit2 = false; // We've bounced
                         return;
                     }
 if (hitInfo.collider.name == "Cube")//is collider the collider we want to set the high speed bounce behavior to
                     {
                         doThisShit2 = true; // This is the bool that's here to say we need to do a bounce on a high speed collision
                         doThisShit = false; //This is the first bool I've added, It prevents the drag transform.pos
                         return;
                     }

I now have one more issue, now the waiting behavior on high speed collisions for other type of walls stopped working quite so responsively, a few more glitches/blinks than before. I think I need to tweak this a bit, but it seems I'm on the right track. EDIT: and yeah, the angle of the newly added bounce off on high speed collisions is sometimes the one he came from but it's not a 90 degree angle with the wall, it must be something with the vector3 given to addforce call in the code above...

Sorry to waste this much space to ask this thing in the end, but i thought it was important to get the full picture :)

I'll be happy to post additional codes or whatever if anyone finds this useful.

If you have any improvement suggestions, fell free to add a comment or a reply...

Regards,

Lovre

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

133 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

Related Questions

Sphere bouncing back on edges of aligned objects 0 Answers

Restrict held object movement 0 Answers

Position and collider seem to incorrectly shift when moving object 0 Answers

how to prevent a kinematic rigidbody from going through static colliders 0 Answers

Flying character rigidbody - can't see any static collider 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