- Home /
NES Battle city like movement when turning (teleporting to fit through the gap of blocks without getting stuck)
This is what I'm talking about https://gyazo.com/20bd71273164bd1cfe0f276ecf83e690
As the title say i'd like to make my tank move through the gap smoothly without making the tank collider smaller. For example, if I'm moving right and I'd like to go through a gap between blocks with a pathway leading up, I would teleport in front a bit when the "up" key is pressed.
I was thinking about rounding the numbers using Mathf.Round but I have no clue how to implament that. Would really appreciate any sort of suggestions.
Remove your Square Collider of your tank and use a Circle Collider.
Or $$anonymous$$ake the square collider a trigger and add a Circle Collider for navigation.
Or use 2 objects in different layers in one you put her square collider for collide with bullets, in the other object you use a circle collider to collider with the walls, and change the collision matrix in Physics2D.
I suppose that would work, but I want is that choppy teleporting movement and circle collider does not provide that. It would just slide a bit reducing speed until it fits into the gap.
Answer by TomatoOrgyLT · Nov 02, 2016 at 12:12 AM
Here's an answer I was looking from a guy from youtube called Ivan Enzhaev
Snapping a tank is very simple. For example your tank has width = 32 and it is moving to right (x, y) -> (0, 0) -> (1, 0), (2, 0) -> .... When you press Up key you need to around X coord. For example, I created an array for X: 0, 16, 32 So If you move to right and pres Up key you need to add to Up key handler a calculation of X coord. For example: if X = 14 you need to set for X coord a value = 16
Answer by jmgek · Nov 02, 2016 at 12:54 AM
Don't use Colliders, make a 2D array and set each element to either 1 or 0, If the player moves check the array and if it's 0 don't lerp to that position, if its a 1 lerp the tank to that position. Also this gives you the ability to spawn the world, at startup check if the element is 0 and if so spawn your brick tile.
Try to stay away from any kind of physics!