Hello Everyone i came with new issue the turret is not rotation , i dont why , can some one help me into this ,i 'll share everything i have
Hey Joshi,
Couple things to get you moving.
Firstly, when submitting code with your problem it will be much much easier for people to read it if you paste the text itself into a code block instead of pasting screenshots of the code. Check out this link
Second, I would recommend renaming your ProjectileRef variable in Tank.h with a more accurate description. Perhaps PlayerControllerRef or TankPlayerController etc⌠I assume this is a copy and paste error but reading the code is made that much more difficult when variables donât describe their purpose. If you do change the name remember that if you donât use the editorâs auto renaming functionality youâll need to change the rest of the places where you use that variable to match the new name. If youâre not sure youâve gotten them all. You can try to compile and the compiler should get mad at you if youâve missed any
Finally, onto the problem. I see youâve tried to add some debug logging into these functions;
ABasePawn::RotateTurret
ATank::Tick
This is a great idea for trying to backtrack through the logic and figure out where the âholeâ is in the logic. Unfortunately since both of your prints are printing the same thing it makes it harder to reason about what exactly is and is not working.
Iâd recommend changing the prints and perhaps adding some more. Hereâs a rough idea of what you could add. NOTE This is just partial code and I havenât check/compiled it so there could be typos or errors. (Itâs much harder to copy/paste/modify your example code when it is in screenshot form )
ATank::Tick(float DeltaTime)
{
UE_LOG(LogTemp, Warning, TEXT("Updaing our tank in general"));
if(ProjectileRef)
{
UE_LOG(LogTemp, Warning, TEXT("We have a legitimate controller reference"));
ProjectileRef->GetHitResult... blah blah blah (CHANGE PROJECTILEREF NAME :) )
UE_LOG(LogTemp, Warning, TEXT("Mouse Cursor Hit Result Location is %s"), *HitResult.ImpactPoint.ToString());
RotateTurret(HitResult.ImpactPoint)
}
}
then in BasePawn
ABasePawn::RotateTurret(FVector Locate)
{
UE_LOG(LogTemp, Warning, TEXT("Trying to rotate the turret towards %s"), *Locate.ToString());
... rest of the code
If you try these and let us know what sort of prints youâre getting then it will give us some more insight into the problem.
If youâre not seeing your tank tick at all then weâre not creating it or have disabled updates. Something like that.
If your ticking, but not seeing anything else, then weâve probably failed to get the player controller.
If youâre ticking, getting a hit point and itâs some crazy numbers something else is happening.
etcâŚ
Hopefully youâre still around and find some of this useful, or maybe youâve already solved it for yourself by now. Let me know.
All the best!
Hi Joshi,
I donât actually see anywhere in the code where the turret rotation is handled - this is related to the mouse and the position is determined by calling GetHitResultUnderCursor. This is handled in the Tank.cpp in the Tick.
Have you checked your code against the lecture changes? The code is added in the Lecture Rotating the Turret but I see youâve posted your question at the end of the section.
I suspect youâve missed some code.
I think he has the code block alright for rotation.
ABasePawn::RotateTurret(FVector Locate)
Itâs at the bottom of this image
And ATank derives from ABasePawn so it should call up to that.
He had the method but wasnât being called anywhere. In tank, code responds to the mouse position, in turret it is where the tank is positioned and points at the tank.
The code to position the actual turret is the same for both and located in the base pawn but the method is different to actually tell it when to rotate.
Ah I see what youâre saying beegeedee.
I assumed Joshi was talking about the Tankâs turret. If youâre talking about the hostile red âtowerâ turrets not aiming towards your tank then youâre missing that code altogether Joshi (Or at least havenât provided any screenshots of the implementation). If youâre talking about the turret on top of the tank that you control as the player not aiming, then weâd need some more info.
For the hostile turrets as beegeedee is saying, you should have a separate c++ file for their implementation with something like this
void ATower::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if(InFireRange())
{
RotateTurret(Tank->GetActorLocation());
}
}
He was talking about the tank. The rotate turret method is for both, but the code in Tick is different for both. He was asking about the tank and why it didnât rotate the turret but the code in tank.cpp for the tick wasnât there.
The turrets come later but the same method in the base class is used.
Oh okay. Isnât that code right here in the first image of the 2nd post?
ATank::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
UE_LOG(LogTemp, Warning, TEXT("Updaing our tank in general"));
if(ProjectileRef)
{
FHitResults HitResult;
ProjectileRef->GetHitResultUnderCursor(...insert arguments...);
RotateTurret(HitResult.ImpactPoint)
UE_LOG(LogTemp, Warning, TEXT("It's Working"));
}
}
No, you are right. It is there.
The code isnât 100% correct though as the screen check for the mouse returns a boolean and should only be acted upon when true.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.