void AFPSProjectile::InitVelocity(const FVector& ShootDirection)
{
if (ProjectileMovement)
{
// set the projectile's velocity to the desired direction
ProjectileMovement->Velocity = ShootDirection * ProjectileMovement->InitialSpeed;
}
}
i got this error Error 19 error C2039: ‘InitVelocity’ : is not a member of ‘AFPSProjectile’
I didn’t add or change anything and i am using UE 4.2.1.
ABHProjectile::ABHProjectile(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
// Use a sphere as a simple collision representation
CollisionComp = PCIP.CreateDefaultSubobject<USphereComponent>(this, TEXT("SphereComp"));
CollisionComp->InitSphereRadius(15.0f);
RootComponent = CollisionComp;
// Use a ProjectileMovementComponent to govern this projectile's movement
ProjectileMovement = PCIP.CreateDefaultSubobject<UProjectileMovementComponent>(this, TEXT("ProjectileComp"));
ProjectileMovement->UpdatedComponent = CollisionComp;
ProjectileMovement->InitialSpeed = 3000.f;
ProjectileMovement->MaxSpeed = 3000.f;
ProjectileMovement->bRotationFollowsVelocity = true;
ProjectileMovement->bShouldBounce = true;
ProjectileMovement->Bounciness = 0.3f;
}
/** inits velocity of the projectile in the shoot direction */
void InitVelocity(const FVector& ShootDirection);
You are declaring your function outside of your class, simply move the line after the closing bracket in your class body and you’re done
Here is the code
#pragma once
#include "GameFramework/Actor.h"
#include "BHProjectile.generated.h"
UCLASS()
class ABHProjectile : public AActor
{
GENERATED_UCLASS_BODY()
/** Sphere collision component */
UPROPERTY(VisibleDefaultsOnly, Category = Projectile)
TSubobjectPtr<USphereComponent> CollisionComp;
/** Projectile movement component */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Movement)
TSubobjectPtr<class UProjectileMovementComponent> ProjectileMovement;
/** inits velocity of the projectile in the shoot direction */
void InitVelocity(const FVector& ShootDirection);
};