Question by
DunderAxel · Apr 01, 2019 at 02:13 PM ·
2dcollider2dplatformercastplatformercontroller
2D Cast Problem
hey! im trying to set up a collision system for my 2d platformer and I cannot get this code to work but I dont know why:
//Collision Check
int col_hits = col.Cast(velocity,contactFilter,collisions,velocity.magnitude);
float dist = collisions[0].distance;
if(col_hits != 0){
velocity = Vector2.ClampMagnitude(velocity,dist);
}
//Move Player
transform.Translate(velocity.x,velocity.y,0);
Basically I want it to do a "cast" then move itself to the position where the collision occured, however the result I am getting is that the character is moved just so that it intersects with the collision and is stuck there forever.
Any ideas would be super helpful!
Comment