Training Stream - Tanks vs. Zombies, p.5, Aug 2nd

WHAT
Continuing the “Tanks” C++ stream, and Lauren will be making tanks to fight a zombie onslaught, using Paper2D. Now is the time for CARNAGE! We’ll be implementing damage dealing and taking to our Tank and Zombies.

WHEN
Tuesday, August 2nd @ 2:00PM-3:00PM ET - Countdown
**
WHERE**

**
WHO**

  • Technical Writer )
  • Sr Learning Resource Engineer

Feel free to ask any questions on the topic in the thread below, and remember, while we try to give attention to all inquiries, it’s not always possible to answer’s questions as they come up. This is especially true for off-topic requests, as it’s rather likely that we don’t have the appropriate person around to answer. Thanks for understanding!

Archive:

Hello,

It is been a great time following this course!

One question that is intriguing me is about the placement of the Zombie AI logic.  You have implemented in the Zombie.cpp class but I was thinking if It would make sense to put it inside ZombieBrains as well, for example, what if you implemented a Zombie that can hear the tank when It gets behing the Zombie's back,  Should I have an  AIController or a Zombie based class design ? Do you have any suggestions about AI class design in general ?

Thank you!

Any we could get the source code for this one? :slight_smile:

I think there are a few things to consider here. Overall, I’d say that it’s something of a matter of your preference, since there are multiple approaches that will work. Here are three possibilities:

  1. Put the sensory stuff in a separate component. We have some built-in code for this kind of thing in the form of the AI Perception classes. This is fine, but adding a new component will increase actor size and spawning time, so in a game where you want massive amounts of enemies, especially if the game is on mobile devices, this might not be the best. We had a similar issue with Match3, where we saw framerate drops during big combos (lots of tiles spawning/destroying), and eliminating one of the three components on our tiles alleviated it to a significant degree. However, if you’re making a game with fewer enemies, or at least enemies that don’t all spawn at once, this could be a good idea.
    https://docs.unrealengine.com/latest/INT/Search/index.html?x=0&y=0&q=ai+perception

  2. Putting hearing/vision in the zombie itself is also OK. The question here is what should be inherited from where. If most zombies could be described as having the same perception, but maybe with some different numerical values, then the base class can implement it all and derived classes can override parts. You could adjust variables, e.g. a SightDistance or SightAngle float variable, or maybe some data-defined curves to indicate how strong their vision/hearing should be at a given distance or angle. The curves would be especially useful for something like a stealth game, where the player has multiple factors like a light level, movement speed, body posture (e.g. standing vs crouching vs lying down), camouflage value, floor surface, etc. to multiply in and determine how long it takes for the AI to become suspicious. Presumably, the zombie pawn would then inform the controller of things like “I just heard something odd at (X Y Z)” or “Actor X is now my enemy”. This lets the zombie pawn class handle the personality of the zombie in terms of how it selects targets, while letting the controller decide how to deal with them.

  3. Putting it on the controller is acceptable as well. If you think of the controller as the whole , and the pawn as, well, just a playing piece like a Chess pawn, then the controller could tell the pawn how to behave physically, and could also know why these behaviors are appropriate. This would be better if the zombie’s personality and movement were more intimately linked, and the programmer/designer doesn’t want to make a bunch of function calls going between the two. It would also be good if the difference between enemies wasn’t how they moved physically, but how they chose to use that movement to position themselves, like the ghosts in Pac-Man.

Sorry, this should have been posted here. I’ll see if I can get it to be put into the OP as well, since I can’t directly edit that.

https://forums.unrealengine.com/showthread.php?122906-Tanks!-project-from-August-2-2016-stream

In 4.13,you can’t override (ReceiveDamage)&(Get Health Remaining) in zombie.h anymore,I checked the documentation, it was only being updated to 4.11.

I know how to implement that in BluePrint.

However,I really wish to know how this could be done in c++.

Thanks a lot.

I’m not entirely sure what you mean here. Can you elaborate or clarify this?

When i build the solution, it always say “1>D:/Library/Document/Unreal Projects/Tanks/Source/Tanks/DamageInterface.h(1): error : Invalid class name ‘DamageInterface’. The class name must have an appropriate prefix added (A for Actors, U for other classes).”. Who can tell me how to fix it?

Here is the complete code that I see in that file. I suspect that there shouldn’t be a class just named “DamageInterface”, but instead there should be “IDamageInterface” and “UDamageInterface”. That may be the source of the problem


// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.

#pragma once

#include "DamageInterface.generated.h"

UENUM(BlueprintType)
enum class EDamageType : uint8
{
	Unknown,
	HitWithMissile,
	Crushed,
	ZombieSlap
};

UINTERFACE(MinimalAPI)
class UDamageInterface : public UInterface
{
	GENERATED_UINTERFACE_BODY()
};

/**
 * 
 */
class TANKS_API IDamageInterface
{
	GENERATED_IINTERFACE_BODY()

public:
	virtual void ReceiveDamage(int32 IncomingDamage, EDamageType DamageType) = 0;
	virtual int32 GetHealthRemaining() = 0;
};

Please let me know if this doesn’t work. Also, did you download our project .zip file and get something that doesn’t compile, or is it possible that you edited anything or wrote it out by hand? I think (and hope!) the file we provide for download should work.