- Home /
ways to get Collision2D
In my game i need to get Collision2D contact points in order to perform smooth push back to the collided object. Problem is when i get it from OnCollision2D(Collision2D collision) the actual 2D physics collision performs it's sharp push back and i can't apply it my own custom one. Is there anyway i can get that Collision2D without actually performing the built in physics?
Answer by sysameca · Oct 04, 2014 at 02:32 PM
I just read the Physics collision table and apparently in my case i can get collision messages if one of the object has rigidbody-kinematic(which is actually in my scene the static object) and the other has rigidbody-non kinematic.I am not sure how this can cost on the performance side, but if anyone has some ideas how can one get Collision2D in some other way please do write it.
Answer by siddharth3322 · Oct 04, 2014 at 02:26 PM
You can manually implement collision detection for your game. I have added one example for you that I have used for my game.
void Update ()
{
if (isStartMoving)
transform.position += direction * speed;
}
void OnCollisionEnter2D (Collision2D otherCollision)
{
Vector3 normal = otherCollision.contacts [0].normal;
direction = Vector3.Reflect (direction, normal);
}
Based on direction value I am moving my ball continuously on screen. I think you have to move on for OnTriggerEnter2D method. I don't have checked this thing with it but as per my consideration it work.
Yeah. I never tested how the object will behave if i override the OnCollisionEnter2D, but now when i think about it maybe it could do the trick.I will test this out for sure.