• 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 G0DF4THER · Aug 06 at 12:10 PM · collisionrigidbody2dmovement scriptboxcolliderrigidbody.velocity

My player goes straight through my colider

So I'm making a 2D pizza delivering game and it has been going smoothly so far but I have run into my first issue. I'm using rigidbody2D. velocity controls so I get a continuously moving effect. But when I go over one of my buildings that has a box colider2d attached to it but my player just goes straight through the building without anything happening. This is my movement script. private void FixedUpdate() { //Player Movement if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow)) { rb.velocity = new Vector2(0, speed); spriteRenderer.sprite = carUp; } if (Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow)) { rb.velocity = new Vector2(0, -speed); spriteRenderer.sprite = carDown; } if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow)) { rb.velocity = new Vector2(speed, 0); spriteRenderer.sprite = carRight; } if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow)) { rb.velocity = new Vector2(-speed, 0); spriteRenderer.sprite = carLeft; } if (Input.GetKeyDown(KeyCode.Space)) { rb.velocity = new Vector2(0, 0); spriteRenderer.sprite = carUp; } } I don't know any way of fixing this so any help would be very much apretiated. :)

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by rufopufo · Aug 06 at 12:25 PM

Hi there,

In order to make a collision work, both objects must have a collider2d attached to them. And at least one of them needs a rigidbody. So, make sure, your player has got its collider2d attached too.

If this is not the case, try to change your rigidbody collision detection to Continious instead of Discrete. But your problem does not sound as it this last solution would make it work.

Hope it helped.

Comment
Add comment · 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
1

Answer by mlnczk · Aug 06 at 12:34 PM

As said by @rufopufo make sure both objects have Collider2d attached to them, one of them ( player ) should have rigidbody2d and also check if in Collider2d components there is unchecked box called "Is Trigger". If its checked then uncheck it. If your game is really fast pased consider changing rigidbody's collision detection to Continious or Continous Dynamic and Interpolate to Interpolate

Comment
Add comment · 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
0

Answer by G0DF4THER · Aug 06 at 10:29 PM

I definitely know that both my objects have a box collider 2d and changing the collision detection to continuous did nothing as well as changing interplate to interplate. :/ Thanks for your help though.

Comment
Add comment · 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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

168 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Box Colider not working properly 1 Answer

Box collider (with Rigidbody attached) gets stuck into another Box Collider 0 Answers

Rigid body not colliding with box collider. 1 Answer

Verify Planes collision inside OnMouseOver of another GameObject 0 Answers

Rigidbody player slightly phasing into wall 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges