I don’t think his way is the best way.
I did a little test, and here’s my way to test:
Say I got a platform with a edge collider 2d attached to it, and a character to control.
When moving the character by setting velocity, the character collides with the edge correctly.
When moving the character by setting it’s position directly, the character just goes through that edge.
I’ve just started learning Unity3d, so I am looking forward to here the correct answer, too.
Thanks for the reply.
I also had the best experience when using the velocity…but, maybe this is wrong. Anybody here who is unity (2d) for a lil longer now?
Thanks in advance
velocity is good for physics based character with rigidbody2d. Transform.translate, transform.position … should you use if gameobject dont have rigidbody2d.
i think, the point of the link is:
"Because it resets the velocity every frame! "
Yeah velocity is fine, if you move with transform position an object that have a rigidbody on it it will have a hard time to compensate phsyics and vector movement, and you may notice that if you have a camera following the player everything jitters.
I tried also to uses force with Impulse but is not really smooth, velocity change is the one that is more reliable for me at least.
Well the cheap way is to create physics materials and addthem to walls setting the friction to 0. Problem is you gonna add a lot of cilliders just for that.
THe alternative is to find a way around by calculating your own gravity and force the player to go down. A way is to raycast toward the jump direction, a short ray that when hit something in that direction stop calculating horizontal force against the wall or simply force the rigidbody down with a AddForce.
By the way a suggestion for your code, I see you call transform.rigidbody2D, by using this “shortcut” you are calling a GetComponent everytime accessing it without knowing. I would suggest to cache it at Start or Awake. Eg:
I did as u suggested.
Depending on the horizontal speed I cast 3 rays into the given direction. Upon collision with the “solids” I reset horizontal speed and only apply vertical speed. Works good enough.