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 aayucool2012 · Mar 13, 2013 at 04:51 PM · collisionrigidbodycolliderraycastingrigidbody-collision

Rigidbody not colliding with walls

So, I made a dx ball type game and in the game I added four walls(not rigidbody) as boundaries. But the problem begins when I test the game the ball(rigidbody) bounces off when it strikes the walls but the paddle(rigidbody) passes through the wall when I move it there. My paddle control script-->

 private var ray : Ray;
 private var hit : RaycastHit;
 
 function Update () {
 transform.Rotate(0, 5, 0);
 if(Input.GetMouseButton(0)){
     ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     if(Physics.Raycast(ray,hit)){
     transform.position.x = hit.point.x;
     }
     }
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Rett_ · Mar 13, 2013 at 05:13 PM

Modifying transform.position of a rigidbody directly is in general a bad idea, because it does not apply physics simulation (which includes collision detection).

Ideally, you only want to move rigidbodies around using AddForce. It guarantees the most realistic physics simulation, but can get a bit complicated when you try to move to a specified point in space and stop.

You can control your rigidbody more directly by modifying its velocity vector. For example:

 private void FixedUpdate () 
     {
         Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         float velocityX = mousePosition.x - transform.position.x;
         rigidbody.velocity = new Vector3(velocityX * MOVEMENT_SPEED, 0, 0);
     }

will move your paddle towards the mouse cursor (assuming orthographic view) on the X axis . Paddle speed will be proportional to mouse - paddle distance.

Finally, you can move your rigidbody around using MovePosition method, which simply "teleports" your object and performs collision checks.

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 aayucool2012 · Mar 14, 2013 at 04:31 AM 0
Share

umm.. what is $$anonymous$$OVE$$anonymous$$ENT_SPEED

avatar image aayucool2012 · Mar 14, 2013 at 04:39 AM 0
Share

can you give me the javascript version

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

11 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

Related Questions

How to make an object 'push' my character out of the way upon collision? 0 Answers

rigid bodies passing through one another. 1 Answer

Collider going through walls with box collider.. 1 Answer

Rigidbody colliders 1 Answer

My Character controller is being push a little bit when i'm about the get the coins. How can i possibly detect collision and destroy the coins without actually getting affected by the colliding physics? 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