Third-person shooter - collisions, movement, shooting, NPCs

This is my exploration of Panda3D, in which I try to make a simple third-person shooter game. I will hopefully continue to update this post as the code improves.

At the moment, the game consists of a PacMan character who runs around the map and shoots moving Ghost NPCs. Not much, but then again, not too long ago it wasn’t anything at all.

Unfortunately, all my attempts at integrating physics into my own designs have failed miserably, at times because I don’t seem to understand some of the functions being called, and at times because strange things happen without me knowing why. So this code doesn’t use physics.

That said, I would be happy if more experienced users were to comment on any inadequacies, irregularities or inefficiencies you might see in the code. I like to comment a lot, so much of the code is comments, though there is a dearth of comments in the blast classes right now, as well. First, though, there are a couple of things worth noting:

  • All the models I use are custom, made in Blender.

  • The environment has three subsets - a “terrain” piece for display, a “floorcollider” piece for floor collisions, and a “wallcollider” piece for wall collisions. I think all three of them, including the terrain, are collision-enabled, however.

  • This is a work in progress; it’s improving, but there are still alot of funky things going on.

LATEST UPDATE: There is now a semi-functional minimap/radar at the bottom-right of the screen (see my third post for a description of its limits), and I have somewhat improved ghost pathfinding when faced with walls.

FEATURES:

  • Camera and actor control
  • Collisions for actor, terrain, projectiles, and NPCs (not camera)
  • Animation for the actor and for other NPCs
  • Jumping, and shooting (using a different class)
  • NPCs that move randomly, flee from or pursue the player, and are destroyed when shot
  • Switching between weapon types
  • A score counter that notes the number of ghosts shot
  • A semi-functional radar map

DOWNLOAD

I would recommend you download the models along with the code, which I have put up here. The full code is massively huge, so I’m afraid I’m going to stop posting it here directly; in any case, there are a lot of custom models and textures in use.

filefront.com/17136148/Shoot … nment.zip/

INSTRUCTIONS:

WASD - character movement
E - jump
Space - shoot
ESC - exit
Up & Down Arrows - Change the actor’s pitch
Left & Right Arrows - Rotate camera around actor
T and H - Zoom in and out
Q - switch ammo types

TO-DO LIST

  • Improve the NPCs’ pathfinding algorithm
  • Implement spawn points for the player and the ghosts
  • Add ammunition, in the form of collectible PacPoints
  • Add special power-ups
  • Make the Red Ghosts attack the player
  • Create an all-around prettier GUI
  • Fix the issues with the radar’s proportionality
  • Make the number of Red Ghosts relative to the number of Blue Ghosts slowly increase over time, thus increasing difficulty (once they are made to attack)

KNOWN ISSUES:

  1. Sometimes, the actor stops being able to jump at all, presumably because self.jump has become stuck at 0. This can be rectified by falling off ledges, jumping while standing on the edge of a platform, or sometimes by repeatedly pressing the jump key. I am not sure why this happens, or how to fix it.

  2. Occasionally colliding with corners will cause the actor to become temporarily stuck, unable to turn and forcing you to retreat; I am not sure why this happens, or how to fix it.

  3. Shooting at the ramps or other parts of the floor doesn’t destroy the projectiles; this is because the projectiles are only set to collide with the floor mask.

  4. The game sometimes crashes if the ghosts are herded into a corner and try to flee through walls. I am trying to set the algorithm up such that they avoid getting stuck like this at all.

  5. Ghosts will occasionally become stuck at corners, even though they are supposed to avoid walls. I am considering a few different fixes for this.

  6. If starting the game with the menu, there is a slight performance drop in a period shortly after the game loads, before performance returns to normal. I am considering why this might be.

  7. The minimap does not provide an exactly proportional representation; pips only move towards the center when the ghost gets extremely close, meaning it would not be very useful if you really needed to watch your back with it. I’m not sure why this is, and I’m trying to fix it.

Since the code has come a long way since my first post, I decided to post a second time, to let anyone watching know that I now have moving NPCs that try to flee from the player when the player approaches, and a scoreboard that tells you the number of ghosts you’ve shot.

The NPC’s fleeing algorithm is primitive, though, so it’s easy enough to “trap” them by getting them in a corner, because they will always try to go directly away from the player. Be warned, however, this might lead to a crash; it happened to me once.

The latest code, and a zip folder, are available in the main post.

Current list of things to do:

  • Have the game automatically generate ghosts, such that there are always a couple running around.
  • Add enemy ghosts that try to attack the player.
  • Add a second weapon type and experiment switching between the two.
  • Have PacMan collect floating yellow pips to refill his ammo.
  • Find a way to make the game load PacMan upon initialization, without crashing.
  • Refine the code.

This is looking really interesting good job!

Unfortunately… I just recently started coding in C++ (tried python for a bit) so I can’t really give any input (yet)

But good job!

Edit:
After trying out the game good start! One difficult thing I had was trying to actually shoot the guys (with such a large area the ghosts could be in, shooting straight or shooting diagonal (the green shots I am assuming are diagonal) essentially limits the person’s ability to hit correctly.

Overall, good job at a good start! Although I don’t think the ghosts attack or do anything (I’ve already run over like atleast three ghosts)

Thanks for the feedback! It’s nice to know it works for other users as well.

I admit, it is indeed very incomplete at the moment. I am going to implement mouse aiming at some point, which should make aiming a lot easier than with the keyboard. Also, the green shots have a random scatter component; the idea is that when I implement ammo, the fast, accurate red shots will be expensive in ammo points and reloading time, but more likely to hit, while the green ones move slower and are inaccurate, but will be cheaper on ammo reserves and faster to fire. As there is no ammo at the moment, however, it’s best just to fire off waves of green until things die.

The ghosts don’t do anything at all at the moment other than move and pursue/flee; that’s intentional. I want to make the red ghosts attack and kill the player, but that will come later; for the moment, the red ghosts and their pursuit behavior makes them more useful for testing things like the radar or pathfinding than the blue ghosts, who just run away from me, so I almost exclusively use the reds for testing.

Also, I will implement a more corridor-like environment in the future, maybe with some platforming elements, though for now, it’s all just a testing ground.

Again, thanks for the feedback! I have just implemented a semi-functional radar map in the newest version, though there are problems with proportionality; though the radar detects from the proper distance, pips only start moving towards the center when the actual ghost is very, very close. It seems the coordinates aren’t being scaled properly. In any case, I’ll put the newest version up, which also includes slightly improved pathfinding for the ghosts.

The view is choppy/jittery when I rotate the camera around. Not during movement, just when I use the arrow keys. Also shouldn’t the menu window be destroyed when the game window launches? I get a reduction in FPS unless I minimize the empty menu window.

Well this is awkward
The link to your code base is 404’d