Author Topic: why can't sprite A collide sprite B ?  (Read 3657 times)

hangingfan

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 5
    • View Profile
why can't sprite A collide sprite B ?
« on: July 07, 2014, 06:43:18 AM »
Hi,guys.
I'm using NGUI 3.6.0, Unity4.3.4f1.
I want sprite A collide sprite B, so that sprite B can also be moved. I attach "Box Collider 2D", "Rigidbody 2D" to A and B.
they both are at the depth 3.
and A has an unique script "RandomForce" to give A a force (wrotten by myself). below is the content:
" rigidbody2D.AddForce (new Vector2 (10, 10)); "




but when I clicked "Run" button, A didn't touch B and then move away. Could anyone tell me what's the problem with my code. thanks sincerely.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: why can't sprite A collide sprite B ?
« Reply #1 on: July 08, 2014, 08:37:09 AM »
What's your collision matrix like?

I just tried the following:

1. New scene.
2. ALT+SHIFT+S to add a sprite, ALT+SHIFT+C to add a collider.
3. NGUI menu -> Extras -> Switch to 2D colliders
4. Changed the sprite's collider to not be a trigger type.
5. Added a 2D rigidbody to the sprite.
6. Duplicated the sprite, changed its dimensions, rotated it and enlarged it to create another surface below the first sprite.
7. Set the 2nd sprite to be kinematic.
8. Hit Play, first sprite falls onto the second sprite and rolls away.

hangingfan

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: why can't sprite A collide sprite B ?
« Reply #2 on: July 08, 2014, 08:41:13 PM »
Thank you for reply.
What's the collision matrix?  I don't understand.
And where is your 3rd step option? I can't find it on my NGUI. Could you screenshot a pic to me? thank you.
« Last Edit: July 08, 2014, 10:53:14 PM by hangingfan »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: why can't sprite A collide sprite B ?
« Reply #3 on: July 09, 2014, 04:04:25 PM »
Collision matrix is located in: Edit -> Project Settings -> Physics 2D

For the 3rd option you need to update. You are 6 versions behind the latest.

hangingfan

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: why can't sprite A collide sprite B ?
« Reply #4 on: July 11, 2014, 07:56:56 PM »
I've updated to the newest version but still unwork.
maybe NGUI can't have a good compatibility with box collider, I've dropped NGUI for this time and the box collider works fine.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: why can't sprite A collide sprite B ?
« Reply #5 on: July 11, 2014, 09:27:59 PM »
Try following my steps. They work just fine on my end.