# Projectiles move (after shot) when charater move

**URL:** <https://forums.unrealengine.com/t/projectiles-move-after-shot-when-charater-move/367211>\
**Category:** World Creation\
**Tags:** projectilemovement, gun, unreal-engine, projectile, question\
**Created:** [August 15, 2016, 4:39pm UTC](https://forums.unrealengine.com/t/projectiles-move-after-shot-when-charater-move/367211 "2016-08-15T16:39:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mBrock](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mBrock](https://forums.unrealengine.com/u/mBrock)\
**Post date:** [August 15, 2016, 4:39pm UTC](https://forums.unrealengine.com/t/projectiles-move-after-shot-when-charater-move/367211/1 "2016-08-15T16:39:36Z")

</div>

I’m using the ProjectileMovement for a lazer gun … small stretched out sphere.

if I stand still they fire in a straight line…

[![](https://d3kjluh73b9h9o.cloudfront.net/original/3X/2/f/2f0984456f8dd47c5beb0a68b72c3d6cf62ef2aa.jpeg) ](http://tinypic.com/images/goodbye.jpg)

but if I rotate the character all the projectiles start to move … even the ones that were shot a while ago.

[![](https://d3kjluh73b9h9o.cloudfront.net/original/3X/2/f/2f0984456f8dd47c5beb0a68b72c3d6cf62ef2aa.jpeg) ](http://tinypic.com/images/goodbye.jpg)

I don’t want the projectiles I already shot to change direction  
The pics don’t show whats happening as much as I would like … the projectiles start to move down up … all over the speed I have set is 350 so the second pic those projectile were shot 10 seconds earlier and I rotated fast…

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_08bdc5fd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_08bdc5fd](https://forums.unrealengine.com/u/anonymous_user_08bdc5fd)\
**Post date:** [August 15, 2016, 5:41pm UTC](https://forums.unrealengine.com/t/projectiles-move-after-shot-when-charater-move/367211/2 "2016-08-15T17:41:48Z")

</div>

Are you spawning the projectiles attached to the player? Might want to show the BP or c++ dealing with spawning the lazers

---

<div class="post-metadata">

**Author:** ![mBrock](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mBrock](https://forums.unrealengine.com/u/mBrock)\
**Post date:** [August 15, 2016, 6:16pm UTC](https://forums.unrealengine.com/t/projectiles-move-after-shot-when-charater-move/367211/3 "2016-08-15T18:16:36Z")

</div>

yes there attached to a arrow component coming out of the gun…

```
void AWeaponBase::OnShoot_Implementation(UWorld* world, APawn* gunOwner, float attackPower)
{
	AActor* weapon = SpawnBullitBP<AActor>(GetWorld(), BPBullit, ProjectileSpawnPoint->GetComponentLocation()/*+ (ProjectileSpawnPoint->GetForwardVector() * 100)*/, ProjectileSpawnPoint->GetComponentRotation());
	
	AAmmoBase* projectile = Cast<AAmmoBase>(weapon);
	if (projectile != NULL)
	{
		FVector const LaunchDir = ProjectileSpawnPoint->GetForwardVector() * 100;
		// place it at the barrel of the gun
		projectile->AttachToComponent(ProjectileSpawnPoint, FAttachmentTransformRules::SnapToTargetIncludingScale, "");
		projectile->InitStats(_AttackRange, _Damage);
		projectile->InitVelocity(LaunchDir);
	}
}

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

---

<div class="post-metadata">

**Author:** ![mBrock](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mBrock](https://forums.unrealengine.com/u/mBrock)\
**Post date:** [August 15, 2016, 6:19pm UTC](https://forums.unrealengine.com/t/projectiles-move-after-shot-when-charater-move/367211/4 "2016-08-15T18:19:04Z")

</div>

oh and ProjectileSpawnPoint is the ArrowComponet

---

<div class="post-metadata">

**Author:** ![TerrifyngTurtle](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TerrifyngTurtle](https://forums.unrealengine.com/u/TerrifyngTurtle)\
**Post date:** [August 15, 2016, 6:59pm UTC](https://forums.unrealengine.com/t/projectiles-move-after-shot-when-charater-move/367211/5 "2016-08-15T18:59:53Z")

</div>

**FYI in case it matters I was doing this all in Blueprints.**  
I had the exact same problem. I had the projectile velocity set to the forward vector of the arrow. I fixed it by just setting the projectiles x-axis velocity to the speed I wanted it to travel at. I’m guessing projectile velocity is relative to the projectile and by using the forward vector it added velocity to the projectile’s other axi even though I just wanted it to shoot in the direction I was aiming. And I’m guessing you’re doing the same thing too in line 22. Try taking out ShootDirection from line 22 maybe (or maybe line12). Sorry I’m not a programmer.

---

<div class="post-metadata">

**Author:** ![mBrock](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mBrock](https://forums.unrealengine.com/u/mBrock)\
**Post date:** [August 15, 2016, 8:05pm UTC](https://forums.unrealengine.com/t/projectiles-move-after-shot-when-charater-move/367211/6 "2016-08-15T20:05:09Z")

</div>

I took off attachtocomponet and initial speed 0 and just used velocity.X … it fixed the bullets moving with the character… but now its shooting in the direction the gun is in idle … when the weapon is first spawned in the hands …  
When the animation raises his hands it still shoots where the gun was spawned.

```
AWeaponBase::AWeaponBase()
{
 	// 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;

	_ItemType = EItemType::IE_WEAPON;

	WeaponMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("WeaponMesh"));
	WeaponMesh->AttachToComponent(RootComponent, FAttachmentTransformRules::SnapToTargetIncludingScale, "");

	ProjectileSpawnPoint = CreateDefaultSubobject<UArrowComponent>(TEXT("ProjectileSpawnPoint"));
	ProjectileSpawnPoint->AttachToComponent(WeaponMesh, FAttachmentTransformRules::SnapToTargetIncludingScale, "");
}

```

and updated the code where I spawn the bullet

```
void AWeaponBase::OnShoot_Implementation(UWorld* world, APawn* gunOwner, float attackPower)
{
	
	AActor* weapon = SpawnBullitBP<AActor>(GetWorld(), BPBullit, ProjectileSpawnPoint->GetComponentLocation(), ProjectileSpawnPoint->GetComponentRotation());
		
	AAmmoBase* projectile = Cast<AAmmoBase>(weapon);
	if (projectile != NULL)
	{
		//FVector const LaunchDir = ProjectileSpawnPoint->GetForwardVector();
		projectile->InitStats(_AttackRange, _Damage);
		//projectile->InitVelocity(LaunchDir);
	}
}

```

I created a Blueprint from class … so I could put the arrow at the gun barrel and that’s where I set the x value to 350  
Guessing my code isn’t getting the blueprints ProjectileSpawnPoint (Arrow) its using the values from when the weapon object was made … not sure how to get the blueprints arrow location and rotation

---

<div class="post-metadata">

**Author:** ![TerrifyngTurtle](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TerrifyngTurtle](https://forums.unrealengine.com/u/TerrifyngTurtle)\
**Post date:** [August 15, 2016, 8:36pm UTC](https://forums.unrealengine.com/t/projectiles-move-after-shot-when-charater-move/367211/7 "2016-08-15T20:36:54Z")

</div>

Is the arrow attached to the weapon? line 4 you have projectile spawn point twice. I dont know if that’s right as I dont program. I haven’t worked much with characters with more than one weapon. Worst case maybe look at the location of your arrow and use that as an offset from your weapon’s location to spawn from? So if in BP your arrow/weapon’s muzzle is at x=100,y=0, Z=0, make that your projectile spawn point offset.
