Search Unity

Hitbox problem with a Sprite (Beginner)

Discussion in '2D' started by StealthOrc, Feb 12, 2016.

  1. StealthOrc

    StealthOrc

    Joined:
    Dec 13, 2015
    Posts:
    10
    Hey there,
    I just began in December to program / get into Unity and C# so I'm a total beginner here. (Learning like Java in school for half a year now) I want to participate in some contests in the future ... but that doesn't matter right now. ^^"
    So I tried myself on a kinda Flappy Bird clone (http://anwell.me/articles/unity3d-flappy-bird/) I also got it covered to convert some of the stuff written there to get it align with the source code of this unity version but I still got a Problem with the colision / hitbox of my rocks beacause it feels to me that they do not get set to the same position as I randomize the rocks position (so the colision polygon isn't moving as it should be) and so I get to some weird things happening which shouldn't like: https://gyazo.com/5cf9a5cdf67c9d0e9189dc394e1c1828 .
    And sometimes it's the opposite where it reloads the scene beacause it seems to hit a collider where no sprite is (so there also shouldn't be a collider! o_O)

    If someone could help me that would be nice, due to the fact that I just started working with unity.
    Heres my project folder, if that's easier to work / help with.
     

    Attached Files:

    Last edited: Feb 12, 2016
  2. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Have you checked it in the inspector to see if the hit box issue is on the prefab rocks or your plane? If the collider is on the rock prefab it will be instantiating in the same position in relation to the rock each time.
     
  3. StealthOrc

    StealthOrc

    Joined:
    Dec 13, 2015
    Posts:
    10
    Well I already tried to lower the inaccuracy of the colliders of the rocks (which made the collision a bit smoother)

    So you mean like the Polygon Collider would be bigger than the actual sprite? if so, as you can see it's not (actually its just a bit tinier) but even though sometimes the plane flies through the rocks (which is okay beacause the collider is a bit smaller) but sometimes it just reloads the scene when there's just "Air". :eek: (like nothing)
     
  4. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    I'd try playing it in the inspector so you can see all the colliders etc first because you seem to be getting different reactions.

    If you can't see anything then put a debug log into the collision check so you can work out if the collision is being called but then nothing is happening or if it is being called even when you can't see anything. If all your prefabs etc are tagged you can get the debug to return what it is colliding with.
     
  5. StealthOrc

    StealthOrc

    Joined:
    Dec 13, 2015
    Posts:
    10
    What do you mean by "playing it in the inspector?" If I try to select / set the focus of something it just deselects it when the Scene gets reload ... o_O (sorry for that question but really don't know what you mean! :eek:)
     
  6. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    You have 2 Windows, one is the editor (which is what I meant, sorry) & the other is the game view. Play it in the editor have your plan selected in the inspector so you can see its collider
     
  7. StealthOrc

    StealthOrc

    Joined:
    Dec 13, 2015
    Posts:
    10
    Oh okay, well I dont really see anything there o_O (so the colliders dont really slack off / I dont see any collision boxes which arent on the sprites :eek:)
     
  8. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Time to put a debug log into the collision code
     
  9. StealthOrc

    StealthOrc

    Joined:
    Dec 13, 2015
    Posts:
    10
    Like that? (In this case the player (plane) collided with the RockPair)

    And yeah it is getting called even if there should be nothing but collides with something ...
     
  10. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Yeah, like that. If you put a break point in & run debug the game will pause when it collides & you can then have a look at what is on the screen. Post a screenshot of that when it happens & show the inspector as well.
     
    theANMATOR2b likes this.
  11. StealthOrc

    StealthOrc

    Joined:
    Dec 13, 2015
    Posts:
    10
    So thats it player inspector:
    rocks inspector:
     
  12. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Try changing the collision detection to continuous.
     
  13. StealthOrc

    StealthOrc

    Joined:
    Dec 13, 2015
    Posts:
    10
    So like that?

    Still doesnt work o_O
     
  14. StealthOrc

    StealthOrc

    Joined:
    Dec 13, 2015
    Posts:
    10
    Oh I think I solved it right now ... Was quite dumb ... I think it was due to the fact the I move the player -2 on the Z pos and the rockpair -5 on the Z pos (beacause as I watched again and again I saw that the Scene cam was matching with the collision ... but the game cam wasn't)
    But as I tried a buch of stuff with the Z Axies I saw that when I set the rocks / player (without reloading the level as it collides of course) to -1 on the Z Axies they just spawn behind the background (0 on Z Axies) and in the middle they pop up in front and as it moves on to the left it disappears again. Some explanation for that? (Even tho I got that fixed by setting it to -2 on Z Axies) but still interesting.

    Even now (at -2 Z pos) it isnt "poping"(?!) in right o.o
     
    Last edited: Feb 13, 2016
  15. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    There are some tutorials on flappy bird clones, I think there may be an official unity one but if not @BoredMormon has done one. Now that you've narrowed it down you can target those tutorials to see what they did.
     
    Kiwasi likes this.
  16. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    That's odd. Physics2D should ignore the z axis completely. Unless you have the whole scene at some weird rotation? Turn the inspector back to normal mode and make sure rotation of everything is 0,0,0
     
  17. StealthOrc

    StealthOrc

    Joined:
    Dec 13, 2015
    Posts:
    10
    Thats the weird thing ... there's no rotation ... on nothing! And that bothers me but I even though as mentioned I solved that kinda by just having a bigger distance between the background and the sprites (on the Z axies) xD well well weird ^^"

    But still if you got any tipps for me on learning Unity just tell me, maybe some methods / projects to work on! :)
    (Beacause I still seems kinda weird to me, to just copy and paste code of someone else and just let it run, maybe setting up the scene and try to learn out of that but otherwise I seem to be planless ... totaly o_O)
     
  18. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Do the unity tutorials in the learn section. You can follow along (the assets used are free to download) & they explain what they are doing & why they are doing it. Bored Mormon also has some that are worth watching.

    Out of curiosity, your background doesn't have any colliders on it does it? & all your Sprite prefabs are at 0,0,0 rotation?

    If you are using layers, set everything to ignore the background.
     
  19. StealthOrc

    StealthOrc

    Joined:
    Dec 13, 2015
    Posts:
    10
    Yeah, no colliders and all sprite prefabs are at 0,0,0 rotation! (going to try that ignore background)