# Error with ProjectileMovement-\>Velocity in FPS Tutorial

**URL:** <https://forums.unrealengine.com/t/error-with-projectilemovement-velocity-in-fps-tutorial/312464>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [March 25, 2015, 12:06am UTC](https://forums.unrealengine.com/t/error-with-projectilemovement-velocity-in-fps-tutorial/312464 "2015-03-25T00:06:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_bb1b6aa21](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_bb1b6aa21](https://forums.unrealengine.com/u/anonymous_user_bb1b6aa21)\
**Post date:** [March 25, 2015, 12:06am UTC](https://forums.unrealengine.com/t/error-with-projectilemovement-velocity-in-fps-tutorial/312464/1 "2015-03-25T00:06:31Z")

</div>

Hey guys, I’m currently working on the [FPS tutorial](https://wiki.unrealengine.com/First_Person_Shooter_C%2B%2B_Tutorial#Projectiles_Interacting_with_the_World) on their wiki page. I’m on the part dealing w/ how to deal when colliding in physics. It has me create an OnHit function, and inside that inside an if check, it has me adding an impulse at location function. It wants me to use ProjectileMovement-\>Velocity \* 100.0f as the 1st param. When I try to compile it says that ProjectileMovement is an undeclared variable. It is declared, and I’m using it in the constructor. Anyone know why it’s saying this, and how to fix it?

FPSProjectile.h

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

#pragma once

#include "GameFramework/Actor.h"
#include "FPSProjectile.generated.h"

UCLASS()
class FPSPROJECT_API AFPSProjectile : public AActor
{
	GENERATED_BODY()
	
public:
	// Sets default values for this actor's properties
	AFPSProjectile(const FObjectInitializer& ObjectInitializer);

	// Called when the game starts or when spawned
	virtual void BeginPlay() override;
	
	// Called every frame
	virtual void Tick( float DeltaSeconds ) override;

	/ **Sphere Collision Component** /
	UPROPERTY(VisibleDefaultsOnly, Category = "Projectile")
		USphereComponent* CollisionComponent;

	/* Projectile movement component */
	UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Projectile")
		UProjectileMovementComponent* ProjectileMovement;

	/* init's velocity of the projectile in the shoot direction */
	void InitVelocity(const FVector& ShootDirection);

	// called when projectile hits something
	UFUNCTION()
		void OnHit(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);

};

```

FPSProjectile.cpp

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

#include "FPSProject.h"
#include "FPSProjectile.h"

// Sets default values
AFPSProjectile::AFPSProjectile(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
 	// 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;

	// Use a sphere as a simple collision representation
	CollisionComponent = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("CollisionComponent"));
	CollisionComponent->InitSphereRadius(15.0f);
	RootComponent = CollisionComponent;
	CollisionComponent->BodyInstance.SetCollisionProfileName("Projectile");
	CollisionComponent->OnComponentHit.AddDynamic(this, &AFPSProjectile::OnHit);

	// Use UProjectileMovementComponent to govern this projectile's movement
	ProjectileMovement = ObjectInitializer.CreateDefaultSubobject<UProjectileMovementComponent>(this, TEXT("ProjectileComponent"));
	ProjectileMovement->UpdatedComponent = CollisionComponent;
	ProjectileMovement->InitialSpeed = 3000.f;
	ProjectileMovement->MaxSpeed = 3000.f;
	ProjectileMovement->bRotationFollowsVelocity = true;
	ProjectileMovement->bShouldBounce = true;
	ProjectileMovement->Bounciness = 0.3f;

	// die after 3 seconds by default
	InitialLifeSpan = 3.0f;

}

void AFPSProjectile::InitVelocity(const FVector& ShootDirection)
{
	if (ProjectileMovement)
	{
		// set the projectile's velocity to the desired direction
		ProjectileMovement->Velocity = ShootDirection * ProjectileMovement->InitialSpeed;
	}
}

void OnHit(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
	if (OtherActor /*&& (OtherActor != this)*/ && OtherComp)
	{
		OtherComp->AddImpulseAtLocation(ProjectileMovement->Velocity * 100.0f, Hit.ImpactPoint);
	}
}

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

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

}

```

---

<div class="post-metadata">

**Author:** ![MarcAndreG](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MarcAndreG](https://forums.unrealengine.com/u/MarcAndreG)\
**Post date:** [March 25, 2015, 12:11am UTC](https://forums.unrealengine.com/t/error-with-projectilemovement-velocity-in-fps-tutorial/312464/2 "2015-03-25T00:11:14Z")

</div>

Are you using 4.7.X ?

If yes, change GENERATE\_BODY for GENERATE\_UCLASS\_BODY and delete

// Sets default values for this actor’s properties  
AFPSProjectile(const FObjectInitializer& ObjectInitializer);

from your .h

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_bb1b6aa21](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_bb1b6aa21](https://forums.unrealengine.com/u/anonymous_user_bb1b6aa21)\
**Post date:** [March 25, 2015, 1:38am UTC](https://forums.unrealengine.com/t/error-with-projectilemovement-velocity-in-fps-tutorial/312464/3 "2015-03-25T01:38:35Z")

</div>

I’m using 4.7.3. Just tried that, and it is still saying that ProjectileMovement is an undeclared identifier.

---

<div class="post-metadata">

**Author:** ![MarcAndreG](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MarcAndreG](https://forums.unrealengine.com/u/MarcAndreG)\
**Post date:** [March 25, 2015, 3:14am UTC](https://forums.unrealengine.com/t/error-with-projectilemovement-velocity-in-fps-tutorial/312464/4 "2015-03-25T03:14:45Z")

</div>

Hey hornfreak ,

Sorry about that quick answer I was not on my main PC with UE4.

So I gave a go at your code and changed a few things but I think your main problem comes from your declaration of the OnHit function. It’s not scoped to the projectile class

If you add AFPSProjectile:: before it in your cpp should help you quite a bit.

I also had to add #include “GameFramework/ProjectileMovementComponent.h” to your .h but I find it weird you got that far without the include.

That should do it

If there’s anything else I’ll be glad to help

Cheers

- Marc

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_bb1b6aa21](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_bb1b6aa21](https://forums.unrealengine.com/u/anonymous_user_bb1b6aa21)\
**Post date:** [March 25, 2015, 3:23am UTC](https://forums.unrealengine.com/t/error-with-projectilemovement-velocity-in-fps-tutorial/312464/5 "2015-03-25T03:23:06Z")

</div>

Lol, wow I cannot believe I kept missing that. Thanks Marc, that solved it!

---

<div class="post-metadata">

**Author:** ![MarcAndreG](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MarcAndreG](https://forums.unrealengine.com/u/MarcAndreG)\
**Post date:** [March 25, 2015, 11:03am UTC](https://forums.unrealengine.com/t/error-with-projectilemovement-velocity-in-fps-tutorial/312464/6 "2015-03-25T11:03:44Z")

</div>

Glad that solved it

don’t forget tonaccept my answer for better tracking

Cheers

-Marc
