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 andreas777 · Feb 16, 2014 at 02:30 PM · collidersplayer movementcontrol

Box collider doesn't work with player object

So I have this code for the Player's movement but the object which has a Box collider doesn't interact with walls. When it hits a wall that I've made which also has a box collider it passes the wall but I want it to stop when it hits a wall. The ball that I made and all the other objects work fine with my walls but the player object doesnt. Help please! The game is in 2D by the way. Here is the code:

 private var ray : Ray;
 private var rayCastHit : RaycastHit;
 
 function Update()
 {
 
     if(Input.GetMouseButton(0))
     {
         ray = Camera.main.ScreenPointToRay (Input.mousePosition);
         
         if (Physics.Raycast (ray, rayCastHit))
         {
             transform.position.y = rayCastHit.point.y;
         }
     }
 }
Comment
Add comment · Show 4
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 Invertex · Feb 16, 2014 at 03:01 PM 0
Share

This script doesn't look like it's related to anything you're asking about... 2D and 3D colliders do not interact with each other. Use colliders in the Physics 2D section only if you want them to collider with eachother. Or only in the Physics section.

avatar image Jojo B · Feb 16, 2014 at 03:53 PM 0
Share

colliders also wont work unless one of the objects has a rigidbody

avatar image andreas777 · Feb 16, 2014 at 09:53 PM -1
Share

Yeah i understood my mistake, forgive me Iam still a beginner. :P

Could anyone help me to change this code to work with Physics 2D because all of my game works with Physics 2D and this code doesn't.

 private var ray : Ray;
 private var rayCastHit : RaycastHit;
 
 function Update()
 {
 
     if(Input.Get$$anonymous$$ouseButton(0))
     {
         ray = Camera.main.ScreenPointToRay (Input.mousePosition);
         
         if (Physics.Raycast (ray, rayCastHit))
         {
             transform.position.y = rayCastHit.point.y;
         }
     }
 }
avatar image Invertex · Feb 16, 2014 at 11:05 PM 0
Share

Please don't post further questions as answers! :)

This isn't the place to ask multiple questions in one, or to ask for code to be changed, but for answers. The issue there is that you're trying to use the 3D raycast system with the Physics 2D system. Use Physics2D.Raycast.

Here's a list of the Physics2D functions available, Linecast is nice as well. http://docs.unity3d.com/Documentation/ScriptReference/Physics2D.html

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

20 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

Related Questions

How to make camera position relative to a specific target. 1 Answer

Help with SWIPE CONTROLS 0 Answers

Prevent Player from sliding over edges 0 Answers

physics.OverlapSphere colliders 1 Answer

Animated characters does not stay upright with 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