c# – How to make Enemy Wander in 2d topdown unity

Im making a top down shooter in unity. The enemy ai travels straight to the middle before actually wandering when I put in the code. What should I do to fix that?
I copy the code in this video:https://www.youtube.com/watch?v=FdNervYWmcE

using System.Collections.Generic;
using UnityEngine;

public class EnemyWander : MonoBehaviour
    float speed;
    float range;
    float maxDis;
    Vector2 Waypoint;
    // Start is called before the first frame update
    void Start()

    // Update is called once per frame
    void Update()
        transform.position = Vector2.MoveTowards(transform.position, Waypoint, speed * Time.deltaTime);
        if(Vector2.Distance(transform.position,Waypoint) < range)
    void setNewDes()
        Waypoint = new Vector2(Random.Range(-maxDis, maxDis), Random.Range(-maxDis, maxDis));

python – Top-Down Tank Physics with Pygame

I am trying to make a top-down tank shooter game in Python and pygame, but I can’t get the tank movement right. My objective is to make it move forward in the direction it is pointing in which would be the angle variable. I am expecting the answer to change the up and down code and that is fine, it was temporary anyway. Here is the code:

import pygame
from pygame.locals import QUIT
import math

# Initalizing everything
pygame.display.set_caption('Top Down Tank Wars || Cloud Multiplayer')
screen = pygame.display.set_mode((600, 600))

# Loading, converting and coloring the space around the tank_body and
# tank_turret images white.
tank_body = pygame.image.load(
    '../Python Projects/Tank Game/blue tank body.png'
tank_body.set_colorkey((0, 0, 0))

tank_turret = pygame.image.load(
    '../Python Projects/Tank Game/blue tank turret.png'
tank_turret.set_colorkey((0, 0, 0))

class Tank(pygame.sprite.Sprite):
    def __init__(self, startingX, startingY, starting_angle, speed):
        super(Tank, self).__init__()
        self.x = startingX
        self.y = startingX
        self.angle = starting_angle
        self.speed = speed

    def up(self):
        self.y = self.y - self.speed
        return self.y

    def down(self):
        self.y = self.y + self.speed
        return self.y

    def left(self):
        self.angle = self.angle + self.speed
        return self.angle

    def right(self):
        self.angle = self.angle - self.speed
        return self.angle

running = True
x = 300
y = 300
angle = 0
speed = 0.05
tank = Tank(x, y, angle, speed)

while running:
    for event in pygame.event.get():
        if event.type == QUIT:
            running = False

    # Set 'key_pressed' to the key that is being currently pressed
    keys_pressed = pygame.key.get_pressed()

    # Forward and backward manuevers
    if (keys_pressed(pygame.K_UP) or keys_pressed(pygame.K_w)):
        y = tank.up()

    if (keys_pressed(pygame.K_DOWN) or keys_pressed(pygame.K_s)):
        y = tank.down()

    # Turning tank body
    if (keys_pressed(pygame.K_LEFT) or keys_pressed(pygame.K_a)):
        angle = tank.left()

    if (keys_pressed(pygame.K_RIGHT) or keys_pressed(pygame.K_d)):
        angle = tank.right()

    angle = round(angle)
    screen.fill((255, 255, 255))

    # Rotating tank and rendering it
    tank_body_copy = pygame.transform.rotate(tank_body, angle)
        (300 - int(tank_body_copy.get_width() / 2),
         y - int(tank_body_copy.get_height() / 2))

    # Rotating turret and rendering it
    tank_turret_copy = pygame.transform.rotate(tank_turret, angle)
        (300 - int(tank_turret_copy.get_width() / 2),
         y - int(tank_turret_copy.get_height() / 2))


# Quit pygame when main loop has finished

Thanks in advance!!

web development – Building enterprise application from the top-down

I am bombarded with all these notions from OOAD to DDD, TDD, layered architecture and so on, at least for me this is too overwhelming.

So based on the divide-and-conquer strategy, I came up with the idea to build an Web application (and in the same time figure out what it takes and learn along the way ) from the highest level policy to the lowest, so instead of building the infrastructure, I first design and build the domain and application layers, then build the repository, presenter, web routing… all of this guided by TDD.

My question is, how did you learn about all this stuff? Is this a bad/good idea?

I argue that the application layer (and the domain layer within it ) is just an algorithm from the client’s point of view, it takes some input and spits out some output, like an (REST) API for example…

python – Revised Top-Down Dungeon RPG


So far, the game works well, and my only major concerns, are a bullet system, and a collision system between the zombies and bullets, as I’ve tried many different ways to go about those two issues, with no luck. Anyways, if someone were to mind explaining how to implement these two concepts, with the code provided, that would be wonderful.

# --- Imports ---
import pygame
import os
import random
# --- Screen Dimensions ---
SCR_WIDTH = 1020
# --- Colors ---
WHITE = (240, 240, 240)
# --- Game Constants ---
FPS = 60
score = 0
lives = 3
# --- Fonts ---
TNR_FONT = pygame.font.SysFont('Times_New_Roman', 27)
# --- Player Variables ---
playerX = 120
playerY = 100
# --- Dictionaries/Lists ---
images = {}
enemy_list = ()
bullets = ()
# --- Classes ---
class Enemy:
    def __init__(self):
        self.x = random.randint(600, 1000)
        self.y = random.randint(8, 440)
        self.moveX = 0
        self.moveY = 0

    def move(self):
        if self.x > playerX:
            self.x -= 0.7
        if self.x <= 215:
            self.x = 215
            for i in range(1):
                new_enemy = Enemy()

    def draw(self):
        screen.blit(images('l_zombie'), (self.x, self.y))
# --- Functions --
def load_zombies():
    for i in range(8):
        new_enemy = Enemy()
def clip(value, lower, upper):
    return min(upper, max(value, lower))
def load_images():
    path = 'Desktop/Files/Dungeon Minigame/'
    filenames = (f for f in os.listdir(path) if f.endswith('.png'))
    for name in filenames:
        imagename = os.path.splitext(name)(0)
        images(imagename) = pygame.image.load(os.path.join(path, name))
def main_menu():
    screen.blit(images('background'), (0, 0))
    start_button = screen.blit(images('button'), (420, 320))
    onclick = False
    while True:
        mx, my = pygame.mouse.get_pos()
        if start_button.collidepoint((mx, my)):
            if onclick:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
            if event.type == pygame.MOUSEBUTTONDOWN:
                onclick = True
def game(): 


    while True:

        global playerX, playerY, score, lives, enemy

        screen.blit(images('background2'), (0, 0))
        score_text = TNR_FONT.render('Score: ' + str(score), True, WHITE)
        lives_text = TNR_FONT.render('Lives: ', True, WHITE)
        screen.blit(score_text, (20, 20))
        screen.blit(lives_text, (840, 20))
        screen.blit(images('r_knight'), (playerX, playerY))

        heart_images = ("triple_empty_heart", "single_heart", "double_heart", "triple_heart")
        lives = clip(lives, 0, 3)
        screen.blit(images(heart_images(lives)), (920, 0))

        if lives == 0:

        for enemy in enemy_list:
            if enemy.x == 215:
                lives -= 1
        onpress = pygame.key.get_pressed()

        Y_change = 0
        if onpress(pygame.K_w):
            Y_change -= 5
        if onpress(pygame.K_s):
            Y_change += 5
        playerY += Y_change

        X_change = 0
        if onpress(pygame.K_a):
            X_change -= 5
        if onpress(pygame.K_d):
            X_change += 5
        playerX += X_change

        playerX = clip(playerX, -12, 100)
        playerY = clip(playerY, -15, 405)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
# --- Main ---
clock = pygame.time.Clock()
screen = pygame.display.set_mode((SCR_WIDTH, SCR_HEIGHT))
pygame.display.set_caption('Dungeon Minigame')


unity – How can I set up a 3D camera for a top-down game like Enter the Gungeon?

DodgeRollGames, the developers of Enter the Gungeon, tweeted that the game was in fact made in 3D

Screenshot of 3D map from tweet

They tried to explain how they set their camera in this reddit post.
Basically what they said was :

so the walls are tilted 45 degrees toward the camera, and the floors are tilted 45 degrees away from the camera, meaning that each should experience sqrt(2) distortion because of the additional length along the z-axis. However, the vertical (y-axis) floor length shouldn’t be perceptually changed.

The camera is not tilted at all.

Camera: 0 degree tilt.

Walls: +45 degrees tilt.

Floor: -45 degrees tilt.

My question is : What do they mean by “However, the vertical (y-axis) floor length shouldn’t be perceptually changed”. If I tilt the walls and floors by 45 degrees and -45 degrees as said, the sqrt(2) distorted walls (the walls have Z depth and are perpendicular to the ground) line up nicely, but the ground gets distorted (obviously). So I distort the ground tiles by sqrt(2) but this essentially stretches the ground by 40% so every vertical movement now has to be increased by 40%.

Can somebody explain what’s going on? Any help would be highly appreciated.

c# – How to make an aiming feature in a 2D top-down Unity game?

I’m doing a top-down 2D game like Darkwood and I want to make a feature where by pressing RMB the player aims down the sights, the camera zooms in a bit to simulate tunnel vision, and the camera pans towards where the mouse pointer is at, without leaving the player character outside view.
So far I’ve managed to do something like this.

I’ve tried several ways to stop the camera from moving beyond a certain threshold, but haven’t managed. Another problem I found is that if you’re aiming and moving, the camera does not move with you.

The one I posted works by lerping between the mouse position and the player position, then setting that as the camera’s position. if rmb is not pressed, camera position returns to be centered at the player. To try making the camera move with the player while aiming, I tried summing the player movement vector with the camera’s aiming position. Didn’t work. As soon as one moved, the camera moved sideways significantly, blinding the player.

To try and limit the camera’s distance from target, I tried adding a check for the distance between player and camera. If the distance was higher than x, the block of code that lerped the position between the mouse and player would not be ran. However, this resulted in the camera being stuck when it reached the threshold, unable to move backwards or sideways.

I heard this could also be done with Cinemachine, but I wasn’t able to figure that out either.

I appreciate any help.

c# – How to do topdown collisions properly?

I’m trying to achieve grid/tile based collisions like (A link to the past) here is an article showing it off (sliding off the corners and such) https://oraqia.wordpress.com/2014/07/05/tricks-for-2d-grid-based-character-collision-that-can-work-in-3d-too/ I’m currently using this type of collision test https://pastebin.com/UJ1hzCcv It’s based on deepnights implementation of tile collisions but modified a bit, you have your positionX/Y in the world, TileX/Y is the tile equivalent (my tiles are 16/16), and XRatio/YRatio which is how much into a tile are you so whenever you’re moving into a tile you can clip into it for a certain amount which is nice for making it seem like the player is above stuff and to have more control over it but I’m really looking for someone to show me how I’d go about implementing this kind of collision testing properly I’ve been having so many problems (Getting stuck in 1 pixel in the corners, Snapping on one side while the other u don’t, getting stuck in general/not being able to move when holding diagonals etc) If you could “Explain Like I’m 5” that’d be awesome I’d really like to learn this stuff properly

TL:DR – Trying to achieve Topdown collision detection like a link to the past/stardew (Slide off corners of tiles) and being bug free (Not getting stuck / snapping)

unity – Unity3D URP – How do I approach creating Fog of War for 3D top-down stealth game?

Until recently, camera stacking used to be unavailable in the URP. But with the newest release 2020.1 (released just yesterday), it’s available again. Although with two limitations: It’s unavailable when using the 2D Renderer or when using the VR Multi Pass mode. But there is a promise that this will change “soon™”.

From the documentation linked above:

  1. Create a Camera in your Scene. Its Render Type defaults to Base, making it a Base Camera.
  2. Create another Camera in your Scene, and select it.
  3. In the Camera Inspector, change the Camera’s Render Type to Overlay.
  4. Select the Base Camera again. In the Camera Inspector, scroll to the Stack section, click the plus (+) button, and click the name of the Overlay Camera.

The Overlay Camera is now part of the Base Camera’s Camera Stack. Unity renders the Overlay Camera’s output on top of the Base Camera’s output.

unity – Rotating towards a target in top-down 2D game

I used the following code to rotate a transform towards another. And it’s working fine. However, I want to lerp it over time.

public void RotateToward(Transform target)
  Vector3 from = transform.up; 
  Vector3 to = target.position - transform.position;

  float angle = Vector3.SignedAngle(from, to, transform.forward);
  transform.Rotate(0.0f, 0.0f, angle); 

An example would greatly help.

game design – Approaches on 2D top-down track racing visualisation

I’m considering writing a very simple management style game with the theme being motorsport racing.

I’ve got a good idea how to do the ‘management side’, but the issue I’m having is how to visually render cars and move on a track (something a bit like):

enter image description here

The key points (keeping it simple):

  • the user won’t control the vehicle directly, they are the ‘manager’ (think football manager) – they can decide on a strategy but cannot control the vehicle
  • the car should stay on track (visually) – they may ‘crash’ (along with other events) though
  • the speed it goes around the track is determined by vehicle performance
  • a car will be aware of other near-by cars around the track – for example, if they’re about to be overtaken, they may actually do a slower lap as they are defending – they may collide, along with other events

My initial thoughts are there are two key design elements here, the track and the car.

The track:

  • a track is composed of many segments
  • each segment is stored in an array
  • a segment (I’m not entirely sure here) but one thing it might contain is a 2D array:

(From (this)(https://gamedev.stackexchange.com/questions/149966/approaches-on-2d-top-view-racing-game-track-design) answer gave an approach of using multi-dimensional arrays)
_ _ _ _ _ _ _ _ _ _
| d d x x x d d d |
| d d r r r d d d |
| d d r r r d d d |
| d d r r r d d d |
| d d r r r d d d |
| d d r r r d d d |
| d d r r r d d d |
| d d e e e d d d |
| _ _ _ _ _ _ _ _ |

_ _ _ _ _ _ _ _ _ _
| d d x x x d d d |
| d d r r r d d d |
| d d d r r r d d |
| d d d d r r r e |
| d d d d r r r e |
| d d d d d d r e |
| d d d d d d d d |
| d d d d d d d d |
| _ _ _ _ _ _ _ _ |

Above is a straight and a 90 degree corner – x exit, e entry, r racetrack and d dirt. Maybe I could create a bunch of these and create a track.

Or maybe a simpler version where I define just an entry and exit:

_ _ _ _ _
| d e d |
| d r d |
| d e d |
| _ _ _ |

_ _ _ _ _
| d x d |
| d r e |
| d d d |
| _ _ _ |

The simplified version where I define an entry e and exit x. I can add additional points r and then construct a curve/straight-line based on the x, e and r coordinates?

My idea is that the vehicle will then move across each segment and I can calculate the time it takes to complete that segment. I can then add up all segments which will give me the lap time. With this approach, I can also check the previous/current/next segment to determine if there are other vehicles it needs to defend/attack against.

The car:

  • store all vehicles in an array
  • each vehicle will always be in a segment
  • speed it completes the segment is determined by its performance (and segment characteristics)
  • vehicle can ‘see’ if there are other vehicles in previous/current/next segment and decide whether to overtake/defend.

I think I could make this work, but I’d be really interested to know if there are better/simpler approach – bearing in mind it’s mostly a visualization and the speed and events are determined by my program.