Problems while making Bomberman.

First of all, I’m really new to Unity.

I’m currently using latest Unity and C#. My goal is make Bomberman at any cost for learn Unity. Currently I made some progress. I uploaded it, you can test. And please answer some problems occurred there.

https://dl.dropboxusercontent.com/u/19063820/bomberman/Builds.html

  1. Move with WASD and try pass wall. When you try enough, you just strangely float into sky and lose you control, and Sphere (player) will fall to outer area.
  2. Make bomb with Spacebar while moving. Bomb will always push you their left side. Obviously I don’t want it. But I’ve no idea how to code it correctly.
  3. Spam your bombs. They also make you lose control and push you away screen. I think it’s because of Rigidbody’s physical effect. But if I remove Rigidbody component, my player passing through walls :frowning:
  4. Current map is static drawn. But I want read it from file. ini file contains some symbols for wall, player position, non-destructible walls etc. Where to I start?
  5. Also If you have some time, please see my code and give some improvement helps :slight_smile:

Player control: http://pastebin.com/4vvqPPLz
BombAI: http://pastebin.com/ci85krsB
GameAI (I attached it into main camera, not sure it’s good idea or not): http://pastebin.com/2AaU9xE4

This was the problem for me, adding Cursor.lockState = CursorLockMode.None; to the pause state of my script unlocked the mouse and fixed the issue.

1 Answer

1

First of all, you can just use

Instantiate(bomb, transform.position, Quaternion.identity);

as far as I know. Secondly the problem is that you have a collider for your bomb and because you instantiate it to your own position it will bounce you off.

Secondly the problem with the wall is that it’s too low. Instantiate it a bit higher, if your wall is 1 unit tall, then:

Instantiate(wall, new Vector3(posX, 0.5f, posZ), Quaternion.identity);

Now for reading from file, you need to search for c# reading from file :slight_smile: you could use this as a start:

If you have your line in the line string, you just need to go trough it and evaluate every character in it. To make it simple don’t leave blank space between your chars, so you won’t need to deal with them, and then you can just use a simple for and evaluate the characters

And yeah, create an empty gameObject and rename to GameController and put there your map creator script, not to the camera, it has nothing to do with it :slight_smile:

K, so what you was missing is that when you attached a rigidbody and collider to your object you need to move it with rigidbody.MovePosition so it would react to physics while moving. The phenomenon you where experiencing was that your script moved the object inside the other object and when the physics simulator got in action pushed it out. Another problem I saw was the placing of the bomb, you needed to use Mathf.Round to get the nearest center instead of math.Floor. Another thing which was a problem that you froze the y position of the object but you instantiated a cube on it. So i removed that so even if you instantiate a cube on it it would just push it sideway. Last but not least I increased the z size of your cube, because it was squeezed and looking strange. [18158-bomberman±+grid.zip|18158]

So the complete fixed project is here:

How do I make bomb then?

The same way, just remove the collider from the prefab :) You can do this by dragging the prefab to the scene view, removing the collider component, hitting the apply button in the inspector then deleting the prefab from the scene. ( do this while not in play mode )

if i remove collider, i'll just go through bomb right? that's not right way.

I see, then what you need to do is to turn the collider to a trigger collider and listen to the void OnTriggerExit(Collider other) function. Check if the other.tag="player" and add a player tag to your character. When this if statement is true, change the collider back to a normal collider. I believe this was how the original bomber-man reacted. This way you can place the bomb, it won't trow you off, but when you leave that zone you can't pass it trough again.

I somehow managed that problem. I just removed sphere collider from bomb prefab. i added sphere collider after 0.5 seconds when bomb created. anyway have another question. for make 2 object can't pass each others (in my case my player must not pass through wall and bomb), must i add rigidbody to it? because i don't want add it. it adding some unwanted things like physics.