- Home /
2D Keeping player stuck to a square platform
Hi,
Just looking for advice and to be pointed in the right direction. Don't feel obliged to write and code really suggestions could work too, thanks.
But the issue I'm having is making my character walk around a cube as if it was stuck to it, like walking round a corner of the cube. (described in the screenshots attached)
The way I'm achieving this now is just by adding a:
rb.AddForceAtPosition (-10f * transform.up, transform.position);
This doesnt work completely really since if you walk of the edge to quickly it will just send you of the screen. If you can recommend a better way to do this that would be amazing.
Thanks in advance!!
Answer by Ali-hatem · Mar 19, 2016 at 06:51 PM
disable gravity
add 4 empty game objects with colliders @ the 4 corners of the square
use OnCollisionEnter2D to detect there names or tags to send them to the desired direction example :
void OnCollisionEnter2D(Collision2D coll) { if (coll.gameObject.tag == "Down") rb.velocity = new Vector2(0, -5); }
Would this send you off the screen when you hit the edge? since you wouldn't have fully crossed/went over the corner.
no it will keep you stuck around the square but if you wander which direction should platform take when you start & it didn't collided withe any of the 4 objects just put rb.velocity code in Start()
since Start()
only called once & send the platform to one of the 4 objects.
Your answer
Follow this Question
Related Questions
2D Top Down Character being Pulled down and movement script not working? 2 Answers
How to access two WheelJoint2D from C#? 0 Answers
how do I find out which object is closer to the finish line? 2 Answers
How do I create a grid-based map in the most efficient way? 2 Answers
Mouse Click Walk to Idle Animations 0 Answers