[Solved]How can I fix the range of my impact (?)

Hi Class, I notice when clicking fire the impact is behind the player’s arm instead of hitting the wall. How can I correct this? I posted a Google link to view a video: Any feedback is appreciated :slight_smile:

https://drive.google.com/file/d/1UhtrL4xlkPyfubxQAGhlxA5djDG93qJC/view?usp=sharing

FireArm.cpp

// Fill out your copyright notice in the Description page of Project Settings.


#include "FireArm.h"

#include "Components/SkeletalMeshComponent.h"
#include "Kismet/GameplayStatics.h"
#include  "DrawDebugHelpers.h"

// Sets default values
AFireArm::AFireArm()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	Root = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
	SetRootComponent(Root);

	Mesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Mesh"));
	Mesh->SetupAttachment(Root);

}
void AFireArm::PullTrigger()
{
	UGameplayStatics::SpawnEmitterAttached(MuzzleFlash, Mesh, TEXT("MuzzleFlashSocket"));

	APawn* OwnerPawn = Cast<APawn>(GetOwner());
	if (OwnerPawn == nullptr) return;
	AController* OwnerController = OwnerPawn->GetController();
	if (OwnerController == nullptr) return;

	FVector Location;
	FRotator Rotation;
	OwnerController->GetPlayerViewPoint(Location, Rotation);

	FVector End = Location + Rotation.Vector() * MaxRange;
	// TODO: LineTrace
	FHitResult Hit;
	bool bSuccess = GetWorld()->LineTraceSingleByChannel(Hit, Location, End, ECollisionChannel::ECC_GameTraceChannel1);
	if (bSuccess)
	{
		FVector ShotDirection = -Rotation.Vector();
		UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ImpactEffect, Hit.Location, ShotDirection.Rotation());

	}

}


// Called when the game starts or when spawned
void AFireArm::BeginPlay()
{
	Super::BeginPlay();
}

// Called every frame
void AFireArm::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

FireArm.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "FireArm.generated.h"


UCLASS()
class DISCORDANT_API AFireArm : public AActor
{
	GENERATED_BODY()

public:
	// Sets default values for this actor's properties
	AFireArm();

    void PullTrigger();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:
	// Called every frame
	virtual void Tick(float DeltaTime) override;

private:
	UPROPERTY(VisibleAnyWhere)
	USceneComponent* Root;

	UPROPERTY(VisibleAnyWhere)
	USkeletalMeshComponent* Mesh;


	UPROPERTY(EditAnyWhere)
	UParticleSystem* MuzzleFlash;

	UPROPERTY(EditAnywhere)
	UParticleSystem* ImpactEffect;


	UPROPERTY(EditAnyWhere)
	float MaxRange = 1000;

};

This should be solved later by ignoring the owner in the line trace.

1 Like

Oh, So in the next session or two we will solve this?

Hi Dan, I’m up to the lesson ( 24_SS_UC2 Blending Animations By Booleans) Which is super! but I’m having trouble keeping up and understanding Sam as I write code along side him. Because, the impact asset is not working correct still it is doing the same thing above . In which lesson do we correct this? .Any feedback is welcomed.

According to git “38 Ignoring Actors In Line Traces”

Hi Dan, I looked at my code and matched it to git they are identical I looked at line 38 but don’t know how Ignore actors on that line which lesson does Sam show how implement this? I attached screenshots of git. Do I ignore the actors in the line of code or in the screenshot below Thank you :slight_smile:

38 is not the line number, it’s the UVR number.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms