Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 lhk · Apr 11, 2014 at 09:35 AM · 2dphysicstriggerphysics2d

Get information on ignored collision

I'm trying to program a low wall in a 2D game. The walls I got so far consist of a sprite and a polygon collider. This works fine, the player can't walk through walls. And shots are stopped by the wall, too.

Here's a screenshot:

collision

It's really difficult to get a screenshot fast enough to see the shot before the collision. This is the best I managed. You view the scene from the top down, the objects are drawn in some kind of pseudo 3d. The player can move up/down, right/left. Collisions are registered by a box collider at his "feet". The walls have colliders, too. It gets complicated with the shot. The actual position of the shot is the small grey circle below. That's supposed to be its "shadow". The shadow has a circle collider which is used for collisions. The white v shaped sprite is the shot itself, it's just a simple sprite, child to the shadow gameobject. No collision detection. That all happens on the shadow. The shadow is responsible for movement, too. As time passes the local y coordinate of the shot-sprite child is reduced. It looks as though the shot is falling down.

But now I need to create a low wall. This is actually rather difficult. The player must not walk through this wall, but shots can fly over it. I've set up a special layer for this type of wall and am ignoring collisions with the shots. But I would like to check if the shot is actually high enough to fly over this wall. The shots are falling down really fast. The movement of the shot is implemented with a script that controls speed, orientation, collisions and height. When a collision happens, the height of the shot should be compared to the height of the collider. That means that I need to register collisions between the low wall and the shot.

I didn't find a way to ignore the collision after it happened. Optimally I would like to do something like this:

 void OnCollisionEnter2D(Collision2D collision){
     InfoScript info = collision.gameobjet.getComponent<Infoscript>();
     if(info.height < this.height){
          // ignore collision
     }
     else{
          Destroy (gameObject, 0.5f);
     }

}

But that doesn't seem to be possible. My next idea was to create a trigger and use OnTrigger to check if a collision happened. But it seems like I can only add one PolygonCollider2D. I would need two: One real collider to stop the player from walking through walls. And one trigger to check for collisions with shots

How can I solve this ?

collision_shot_wall.png (190.5 kB)
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
Best Answer

Answer by lhk · Apr 11, 2014 at 11:33 AM

Works now. I just added a child GameObject with the new polygon collider and the info script.

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.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Jitter/vibration on an object with constant velocity when using 2D Pixel Perfect Camera 1 Answer

Script calling onCollisionEnter2D and onTriggerEnter2D while disabled 1 Answer

How do you detect if two specific objects are touching each other without collision. 3 Answers

Trigger behavior between physics(2d) objects 1 Answer

Physics2D Overlapbox not working as aspected 0 Answers


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