Download

C++ Camera Controlled Turrets

So I created a tutorial over here on the wiki: https://wiki.unrealengine.com/C%2B%2B_Camera_Controlled_Turrets

It’s my very first tutorial and quite a lengthy one at that! I finally got off my lazy bum to get it up. I’m making a little redundant post here but I wanted to ask the community for feedback and what they think of the tutorial. Also if any of the decisions I made in the code makes any sense or if if you have a better way.

Love to get some feedback as I had a lot of fun making this tutorial and I’m thinking of making more.

If anyone would be interested, I’m planning on making a tutorial on how to extend this tutorial to make it Network capable with C++ and a little bit of blueprints. But this time I would spend some time speaking about why and how networking is done.

Let me know if you want to see this tutorial!

I think that would be a great and logical extension of the tutorial and would appreciate a new discussion on not only how but why to do some things, often tutorials just go over the how and as often as not its the why that is just or more important to know about! Thanks a bunch!

It’s a wondful work! But how to use the parent class ITurretInterface? Where does the parent class ITurretInterface come from?
More guidance from you will be highly appreciated.
class TURRETTUTORIAL_API ATurretBase : public APawn, public ITurretInterface

I am also trying to get it to work but compile fails at the turretinterface.
Well and the MunitionsBase but I just failed with that one :wink:

Further info would be highly appreciated.
Thank you for this great tutorial!

I also failed to work it out. Could you tell me how to use the parent class ITurretInterface? Where does the parent class ITurretInterface come from?
Thanks a bunch!

Sorry for raising your hopes there, I meant that I also lack the info about it.
So I am basically stuck at the the same point as you.
Maybe IntVoid will notice the activity here and give us some info.

I hope so.
Well, thank you all the same.

I would totally love to see the tutorial extended for networking.

But actually I am mainly quoting you, hoping that you get an email notification and check back here.

Maybe you can point us into the right direction about the TurretInterface.

Still would love network capability for the whole thing!

My apologies! I’ve been wrapped up in my day work and the next tutorial segment that I haven’t been on the forums for a few days.

I’m currently at work, but when I get home today (should be in a few hours) I can look into seeing why the Turret Interface may be causing compile issues for both of you.

First off, I’m extremely happy to know people are using my tutorial and I appreciate any feed back you may have regarding it. Now with the ITurretInterface, could you do me a solid and post me your output compile log for why it may be erroring in compile?

And just looking over the tutorial again, I just noticed a big flaw. I forgot to talk about the creation of the Interface class. I’ll get that amended, I believe that will actually resolve any issues you two may be having with it.

Hi there, thanks for responding!

Seems like you found what was missing without the compile log but here is the error related to the turretinterface anyway:


Error \TurretBase.h(10) : error C2504: 'ITurretInterface': base class undefined

I got more errors but those are mainly related to me not having figured out the Munitions class.

Thanks for looking into it!

Yeah I completely spaced on adding the part where you actually create the base interface class to the tutorial. I feel like a dunce for doing so and possibly giving many people headaches here! When I get home tonight, I’ll make the updates and post the update here as well.

And yeah, that error pretty much confirms my mistake. If you need help with the munitions class later, I can provide assistance!

No hurries man, take your time.
And no worries about people getting stuck with the tutorial, at least for me it helped a lot to understand the whole thing much better since I went through everything line by line and tried to find the missing piece of the puzzle.

You are doing the community a great service so nothing to feel bad about.

Looking forward to the update and I will pick you up on that offer about the munitions class if I get stuck with it :wink:

Thanks! It’s much appreciated! Also here’s the update!

You want to make a new blank C++ file, name it TurretInterface, and put these in respectively.
TurretInterface.cpp



#include "TurretTutorial.h"
#include "TurretInterface.h"

UTurretInterface::UTurretInterface(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{

}

// This is required for compiling, would also let you know if somehow you called
// the base event/function rather the override version
void ITurretInterface::PrimaryFireControl()
{

}


TurretInterface.h



#pragma once

#include "TurretInterface.generated.h"

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

class ITurretInterface
{
	GENERATED_IINTERFACE_BODY()

public:
	virtual void PrimaryFireControl() = 0;
};


This should take care of your compile issues!

Hi, IntVoid! Glad to see your reply. Just as Chairman Meow wrote, no hurries, take your time, we have learned a lot to understand the whole thing much better now, and you are doing the community a great service so you should be proud of your achievements. And for that, I salute you!

Thanks a lot, that one is working now and I fixed the Munitions problems.
*What I am stuck on right now is the Turret Spawn Logic, if I add the part for the ShipBase.h


 // Spawn Turrets
	UPROPERTY(Category = BlueprintSpawn, EditDefaultsOnly, BlueprintReadOnly)
		TSubclassOf<ATurretBase> TurretBP;
	TArray<FName> TurretArray;
	TArray<ATurretBase*> SpawnedTurretArray;
 
	void GetTurretSockets();
	void SpawnTurret(FName _TurretSocketName);
        void DestroyTurrets();

I end up with the error Error: Shipbase.h(66) : error C2065: ‘ATurretBase’: undeclared identifier

Fixed those before by including the right .h but for this one I fail to find my error.*

Got this fixed by cleaning up my dependencies.

Also I found out that replacing AttachTo with SetupAttachment resolves the warnings about AttachTo being deprecated and using AttachToComponent being adviced without needing more arguments.
Not sure how to use that for the AttachRootComponentTo though.

So your issue is resolved?

Also I’ll go ahead and check in on the deprecated warnings and move to update the tutorial farther. Thank you for the input!

EDIT: So I looked into any warnings, and I’m not getting any warnings about AttachTo being deprecated (have the latest version of engine). Is this when your attaching the springarms and cameras?

EDIT2: Okay, so I found the issues, what you want to replace all AttachTo and AttachRootComponentTo to AttachToComponent. Below is specifically the turret spawn logic. For the springarm and camera, omit the turret socket name.



RailGun_T->AttachToComponent(this->RootComponent, FAttachmentTransformRules::KeepRelativeTransform, _TurretSocketName);


You do not need to declare a socket if you don’t want to. But in place for the Turret Spawning, you want to use the Socket name that we want. I’ll update the tutorial for the noted changes.

Thank you very much.
That will probably also solve my problem with the camera not responding to mouse axis input for pitch / yaw although the mouse wheel up / down is working fine for zooming.

And yes, the other problem is solved, that was just me messing up the includes.

First time doing c++ stuff for me and it’s great to have support like this, so thanks again for that!

You’re welcome! Glad I can be of assistance! Feel free to add me to Skype if you wish to bug me for help here and there :slight_smile: I actually just got a C++ implementation of ship movement using physics instead of whats in the tutorial, it’s quite fun spinning out of control now and then! Also congrats on breaking into C++! You can tell it can get quite confusing but fun.