• 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 BallStimulator · Sep 16, 2020 at 07:59 PM · 2d game2d-physicscollision2d2d sprites

Why aren't my 2D sprites colliding properly?

I've looked everywhere on the internet for an answer, but I haven't been able to find one yet, so I'm trying here.

I'm trying to make a very basic game in Unity2D that involves a player sprite being moved via transform.position. The player has a Box Collider 2D, as well as a Rigidbody 2D. I also have a floor sprite as well that just acts as a static box with a Box Collider 2D at the bottom of the screen. The problem is, when the two collide, the player just goes behind the ground without ever being stopped by it. I set up a collision detector in the script, so I know that the game recognizes a collision is happening, but no actual collision occurs.

Here are the inspectors for both objects:

Player: Player's inspector view Ground: Ground's inspector view

Nothing is set to Kinematic, everything is set to 2D, both sprites have their Z coordinates set to 0, the player is moving far too slow to ignore a collider as big as the ground's, and I can't see anything that would make it so they would pass through each other.

I assume the problem is with the player's movement being based on transform.position, but I haven't seen anything online that says that wouldn't work, so I'm stumped at this point. Hopefully someone here can shed some light on the situation. I'll give any extra info I might've forgotten, and many thanks in advance everyone

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
Best Answer

Answer by BallStimulator · Sep 19, 2020 at 01:40 PM

Alright, so I was messing with random attributes and I managed to find the solution!

Turns out, I just had to un-check the "isTrigger" box for both of the objects. I looked at the Documentation page for the isTrigger box, and apparently it disables all actual collision detection.

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 Gustard · Sep 16, 2020 at 08:41 PM

Just because you have the colliders set doesn't mean they will actually do anything in this scenario. You will need to make it so that, on collision, the transform.position method can't move the character forward anymore. This is easiest by setting a speed variable that goes to 0 on collision. If I misunderstood your progress and you have done this already, I would be happy to look over your code and see if I can solve this for you. Just post it in the comments.

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

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

Related Questions

My player is not rotating upwards when it moves upwards. Any advice? 1 Answer

Default Contact Offset Problems 1 Answer

I am very new to unity and I'm looking for advice on a targeting system( or if i'm setting myself up for failure) 1 Answer

Shooter 2D - Problem with rotation of bullet to face direction (velocity) 2 Answers

Best approach for 2d animation to interact with the environment? 0 Answers

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