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 m0mohy92 · Nov 20, 2018 at 04:29 AM · collisiondistancemobilephone

How to stop collision at specific distance?

Hi! I am making a mobile serious game in which a ball destroys a brick when hitting, the ball represents the player hand movement. A counter increases every time collision occur. How to stop collision when distance between the ball and the brick is less than a specific number, i need to force the player to move his hand in specific movements to achieve collision.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by game4444 · Nov 20, 2018 at 04:57 AM

You could calculate the distance between the player and your brick. for Example: float distance = vector3.Distance(player.postion,brick.position); if(distance<2) { // stop player } this is one solution. 2nd solution you could do is you can attach collider with Trigger checked and increase the size of collider where you want to stop your player. And check whenever Player Triggers collider you could stop your player.

Comment
Add comment · Show 5 · 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 Feref2 · Nov 20, 2018 at 05:09 AM 0
Share

Sorry, but that would take the distance from the center, so you should also subtract half of the sphere.

avatar image m0mohy92 · Nov 20, 2018 at 05:24 AM 0
Share

Thanks for reply, I already calculated the distance, i don't want to stop player movement. all i need is to stop collision when the distance is for example less than 4, to force the player to move his hand because it is a forearm rehabilitation serious game.

avatar image game4444 · Nov 20, 2018 at 05:33 AM 0
Share

Could you attach screenshot of your game setup for clear picture of problem. thanks

avatar image m0mohy92 game4444 · Nov 20, 2018 at 05:54 AM 0
Share

The ball should hit the brick 5 times to destroy it, for rehabilitation purpose i made the movement to be only in z-axis at first and calculate distance between the ball and brick every frame, then when reaching 0, the movement is only allowed in the x-axis to hit the brick. After hitting it and the counter is incremented by 1, i need the player to make the same z,x axis movements respectively. I thought of respawning the ball at the start position after collision with the brick, but i feel it will not be realistic, so if there is a method to prevent collision till reaching a specific distance, it would be better,$$anonymous$$any thanks. ![alt text

moderate1.png (47.3 kB)
avatar image game4444 m0mohy92 · Nov 20, 2018 at 07:05 AM 0
Share

what about my second solution using triggered colliders around your brick wall?

avatar image
0

Answer by Feref2 · Nov 20, 2018 at 05:06 AM

It´s difficult to tell because I don´t know a lot of variables, but I can tell you this. With Vector3.Distance you can get the distance between the center of the ball and a point on the brick (depends on what you need). Then just subtract the sphere radius from it and you will get the distance from the edge of the ball, of course, assuming that sphere is completely spherical.

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 m0mohy92 · Nov 20, 2018 at 05:26 AM 0
Share

Thanks for reply, I already calculated the distance, which sphere do you mean? the sphere collider?

avatar image Feref2 m0mohy92 · Nov 23, 2018 at 08:34 AM 0
Share

What do you mean with "which sphere do you mean?" You only have one sphere, the one of the ball. I think the sphere collider has the same size, but if you are not sure how to do it then just use meshFilter.bounds.size.x / 2. You can also use the renderer or the z axis, whatever you need. The meshFilter is really a box I think, but its width is the same. Just draw a circle inside of a square, then a horizontal line from center to edge and you´ll get what I mean. I actually did it, but couldn´t upload the image. By the way, sorry for replying 3 days later. I didn´t saw this until now.

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

148 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

Related Questions

Need advice on non-realistic bullets collision vs distance 1 Answer

Keep minimum distance while moving. 0 Answers

move to next scene 1 Answer

How to handle collisions for LODs with different submeshes? 1 Answer

Rigidbody slows down before touching its target 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