# Projectile Collision

**URL:** <https://forums.unrealengine.com/t/projectile-collision/295799>\
**Category:** World Creation\
**Tags:** projectile-hit, unreal-engine, Collision, projectile, question\
**Created:** [October 10, 2014, 1:45pm UTC](https://forums.unrealengine.com/t/projectile-collision/295799 "2014-10-10T13:45:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_3f36203b](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3f36203b](https://forums.unrealengine.com/u/anonymous_user_3f36203b)\
**Post date:** [October 10, 2014, 1:45pm UTC](https://forums.unrealengine.com/t/projectile-collision/295799/1 "2014-10-10T13:45:28Z")

</div>

Hi all. Following the tutorial on this page

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

I think, I’ve followed everything, but I clearly must have done something wrong because my projectiles don’t collide at all.  
Here is what I have so far.

Header file

```
#pragma once

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

/**
 * 
 */
UCLASS()
class ROM_API AROMProjectile : 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);

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

```

Here is the cpp file.

```
#include "ROM.h"
#include "ROMProjectile.h"

AROMProjectile::AROMProjectile(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;
	CollisionComp->BodyInstance.SetCollisionProfileName("Projectile");
	CollisionComp->OnComponentHit.AddDynamic(this, &AROMProjectile::OnHit);

	// 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;

	// Die after 5 seconds by default
	InitialLifeSpan = 5.0f;
}

void AROMProjectile::InitVelocity(const FVector& ShootDirection)
{
	if (ProjectileMovement)
	{
		// set the projectile's velocity to the desired direction
		ProjectileMovement->Velocity = ShootDirection * ProjectileMovement->InitialSpeed;
	}
}
void AROMProjectile::OnHit(AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
	if (OtherActor && (OtherActor != this) && OtherComp)
	{
		OtherComp->AddImpulseAtLocation(ProjectileMovement->Velocity * 100.0f, Hit.ImpactPoint);
	}
}

```

Any ideas where I’ve gone wrong?  
Thanks in advance everyone! Any help is very much appreciated.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_fc4c82b6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_fc4c82b6](https://forums.unrealengine.com/u/anonymous_user_fc4c82b6)\
**Post date:** [October 10, 2014, 5:31pm UTC](https://forums.unrealengine.com/t/projectile-collision/295799/2 "2014-10-10T17:31:11Z")

</div>

Hi ,

what do you mean by “not colliding”? Is the OnHit Method ever being called? If it is not being called, you should check if the collision settings are correct! (Open the Blueprint → Components → Mark your colliding box/sphere and check if generate Hit events is checked and if its Collision Channels are set correctly!)

[You might check out: [Collision in Unreal Engine | Unreal Engine 5.2 Documentation](https://docs.unrealengine.com/latest/INT/Engine/Physics/Collision/index.html)]

Good luck!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_3f36203b](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3f36203b](https://forums.unrealengine.com/u/anonymous_user_3f36203b)\
**Post date:** [October 10, 2014, 6:58pm UTC](https://forums.unrealengine.com/t/projectile-collision/295799/3 "2014-10-10T18:58:48Z")

</div>

Sorry, by colliding I meant the sphere projectile wasnt bouncing off of objects.

I had enabled collision on the projectile mesh, as opposed to the CollisionComp  
This is how they are set now and that seems to have fixed the collision issue.  
 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/e/1/6e1af6de072f51a6656775424659f1328823d224.png)  
 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/5/6/f56a04c2e58ac76744c9b4f255d7daa2254088e0.png)  
However… For some reason now, the projectiles only shoot in one direction. If i turn or look up and down they always shoot along the X axis in a positive direction. No idea what that could be caused by.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_fc4c82b6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_fc4c82b6](https://forums.unrealengine.com/u/anonymous_user_fc4c82b6)\
**Post date:** [October 10, 2014, 7:59pm UTC](https://forums.unrealengine.com/t/projectile-collision/295799/4 "2014-10-10T19:59:18Z")

</div>

Does your code match the one in the tutorial? Can you post your Fire-Method here? (OnFire?)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_3f36203b](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3f36203b](https://forums.unrealengine.com/u/anonymous_user_3f36203b)\
**Post date:** [October 11, 2014, 6:34pm UTC](https://forums.unrealengine.com/t/projectile-collision/295799/5 "2014-10-11T18:34:53Z")

</div>

As far as I’m aware everything matches up. Unless I’ve made a mistake somewhere.

This is the OnFire method from the ROMCharacter.cpp

EDIT: Code didnt display well on here, switched to pastebin

Thanks again!
