Projectile only moving in X-axis

All of the below did not solve my problem:

I found a workaround:

ProjectileMovementComp->Velocity = GetActorRotation().Vector() * 3000.0f;

But the above workaround should not be required. Looking at the C++ FPS template, firing a projectile only requires this:

	ProjectileMovement->UpdatedComponent = CollisionComp;
	ProjectileMovement->InitialSpeed = 3000.f;
	ProjectileMovement->MaxSpeed = 3000.f;

And this is my code:

 ProjectileMovementComp->InitialSpeed = 3000.0f;
 ProjectileMovementComp->MaxSpeed = 3000.0f;
 ProjectileMovementComp->Velocity = FVector(3000.0f, 0.0f, 0.0f); // replace this line with the workaround.
 ProjectileMovementComp->ProjectileGravityScale = GravityScale;

Changing the UpdatedComponent never did anything for me. Unless I set to a component that is NOT the RootComponent in which case the projectile won’t move at all no matter what you do.

The projectile is also properly rotated. So the projectile may be facing the y-axis, but it is still moving along the x-axis (so it’s moving sideways in this case)… I also paused the playtest, ejected and selected a projectile and tried to change just about every setting I could find but nothing (other than changing the velocity) would make it move in the proper direction.

It’s almost as if the game is somehow using localrotation instead of worldrotation.

I might be misunderstanding here, but in the situation described above it makes perfect sense to me that it would only move in the x-direction. This is simply because that is exactly what your code is telling it to do. Velocity is expressed in world terms, so if you’re instructing the engine to only apply a velocity in the x-direction, that is what it will do.

The workaround you describe is not a workaround as far as I can tell. It is actually giving the projectile the information required. It is in effect telling the projectile to have velocity in the direction that the player is aiming and scale that by 3000.

I suppose I should ask what you expect this line to mean?:

ProjectileMovementComp->Velocity = FVector(3000.0f, 0.0f, 0.0f); // replace this line with the workaround.

Like staticvoidlol mentioned you use a World Direction vor your Velocity (3000x,0y,0z) what you realy want todo ist to get the Forward Vector (thats the direction you are facing, Unitscaled) and multiply it by 3000.

This will give you the correct Movement direction and Scale in Worldspace. You more or less answered your own Question =)

Okay so my “workaround” is an actual proper solution then.

But why does the C++ FPS template work without using the velocity multiplied by the direction? It does not even have the velocity set at all from what I can see. Only the initial & max velocity.

Hmm did you accidently turn off bInitialVelocityInLocalSpace? (C++ or BP) because this will basicly do what you do manually right now. Also you never showed us where you set the rotation and of what you set the rotation? Thats a Potential cause of the Problem all we got is your Word that is already Rotated properly. But maybe you did Rotate the Mesh instead of the root who knows =)

We based everything only on what you showed us.

bInitialVelocityInLocalSpace doesn’t do anything for me.

Regarding the rotation (even though I manually set it during playtesting (eject, pause, select projectile, change stuff, unpause) and it still doesn’t work) and spawning:

if (DefaultShootHandling && (Role == ROLE_Authority))
	{
		ABaseCharacter_C* OwnerCharacter = Cast<ABaseCharacter_C>(OwnerActor);
		ABaseProjectile* BaseProjectile = GetWorld()->SpawnActorDeferred<ABaseProjectile>(ProjectileClass, ProjectileTransform, OwnerActor, OwnerCharacter, ESpawnActorCollisionHandlingMethod::AlwaysSpawn);
		if (BaseProjectile != nullptr)
		{
			BaseProjectile->OwnerCharacter = OwnerCharacter;
			BaseProjectile->CanHitTeams = ULib::GetOpposingTeams(OwnerTeam);
			UGameplayStatics::FinishSpawningActor(BaseProjectile, ProjectileTransform);
		}
		else
		{
			LOG_ERROR("Failed to spawn the projectile into the world.")
		}
	}

Sadly the actual rotation code is rather complicated (involves auto-aim and everything). But I can verify that the rotation is correctly set and that the rotation is put into the ProjectileTransform-variable.

Ok the “eject, pause, select projectile, change stuff, unpause” will most likely not work. Direction is already Set right after Spawn changing the rotation afterwards will not change the Velocity!

What you can try is simply Add the Projectile into your Level before you Start the PIE. Add a couple of them with different rotations. Start the PIE if they all fly in different directions than Im 95% sure your initial rotation you pass at spawn is 0,0,0 try to Log it right before you Spawn the Projectile. Look at this gif 4 projectiles all rotated differently flying in all directions. Thats the default FPS Projectile.

I dragged a projectile into the world (at designtime), gave it a rotation and set the veloctiy to (1000.0f, 0.0f, 0.0f) and made sure that the “Initial velocity in local space” is checked.

It still only moved along hte x-axis. There must be another setting influencing it.

Also the rotation is correctly calculated and correctly set. It’s not the rotation. I can confirm it both visually as well as by stepping in VS. So there has got to be yet another setting influencing the movement direction.

Dont set the Velocity comment out the line completly. If you Set the Velocity you are override what it should be (You tell your Projectile again to move along x with a velocity of 1000). Try again without the Velocity.