Hello Answerhub,
Situation:
I want to create a “Topdown” ship battle game. My first step was to create a pawn without a mesh and attach a camera to it. So the pawn always moves on top of the terrain and the camera follows this pawn. At the same time I have a second pawn. This pawn is the ship. The player can controll the camera and the ship at the same time, but can also attach (focus) the camera on the ship, so that the camera follows the ship movement.
Problem:
So far so good, everything works. Now I want to shoot cannonballs from the ship. The ship has two sides right (true) and left (false). True and false, because I have created a bool which represents the select side. (Sides can be switch with Q and E: When you press Q the bool is updated to false and in my Shoot function the false branche is executed)
I have a Cannonball.h with:
- A UStaticMeshComponent as RootComponent
- A USphereComponent
- A UProjectileMovementComponent
In my Ship.cpp when the Shoot function is executed I want to spawn a cannonball with physics simulated and a launche imulse.
A cannonball should be spawned at a socket,
than added to a TArray and after this fired.
The Ship::Shoot() fuction looks like this:
And the ACannonball::FireInDirection() function looks like this:
I have tried a lot of different things for the last two days, but nothing solved my problem.
At the moment the cannonball is spawned at the socket (“Cannon_r_1”) and has physics enabled, but just drops down and trough the level. (When I look in the “Details” tab of the spawned cannonball at runtime the velocity is updated, but the ball doesn’t move)
But I have tried different things:
-
I’ve followed the Projectile Documentaion:
Implementing Projectiles in Unreal Engine | Unreal Engine 5.1 Documentation but when I do this my actor as no visible Mesh -
I’ve tried it without a ProjectileMoveComponent and just with AddImpule/AddForce nothing happend
-
I’ve set the SphereComponent to RootComponent, but than the actor was spawned at the socket and immediately teleported to ((0, 0, 0)?) or another point. There it just droped again.
-
I’ve tried different CoollisionSettings nothing happend. And when I don’t check the “Simulate Physics” Box the actor is spawned, but stays in the air.
I’ve tried some more things but nothing changed my mess. Mybe someone understands my problem and can help me. If you need more detailed information or the situation is unclear tell me.
Greetings