- Home /
2D Roguelike - moving onto enemies
Hi all,
I've agonized over this for hours now. My code seems to match the tutorial exactly. I've gone back through the tutorial. I've combed my code for logic issues. I just can't find the problem. Everything works as intended EXCEPT I can move the player onto the enemy. I have added debugging code to the "Move" function in MovingObject to detect when hit returns null or with a hit. I've quintuple checked that the Enemy prefabs are on the BlockingLayer layer, as needed. I've checked during runtime that created enemies are on the BlockingLayer layer. The code works will external walls and choppable walls, just not enemies. It's driving me insane.
Thanks!
[SOLVED]
I found my issue -- Collider scale for the enemies. It was set to 0.0001 by 0.0001. The correct values are 1 x 1.
That fixed it, my Player no longer moves through my enemies!
Answer by Moonboss · Jul 22, 2018 at 05:02 AM
Anyone have an answer? I'm having the same exact issue.
Answer by MatheusMiliorini · Oct 26, 2020 at 03:22 AM
Hello! This is a little late, but I believe I've found a solution by using a CircleCast instead of a Linecast. The following code did the trick:
Vector2 start = transform.position; Vector2 end = start + new Vector2(xDir, yDir); boxCollider.enabled = false; hit = Physics2D.CircleCast(start, .5f, (end - start).normalized, 1f, blockingLayer);
Your answer
Follow this Question
Related Questions
How does Unity figure out generic component type as Wall in Project: 2D Roguelike tutorial? 0 Answers
In the tutorial of the 2D Roguelike game, where is the player gameobject instantiated in the code? 2 Answers
For loop in "Writing the Board Manager" 2d Roguelike confusion 1 Answer
How to add a tutorial to the game? 2 Answers
Error after importing assets (Survival Shooter tutorial), Win32Exception 0 Answers