I'm able to fire projectiles fine from an actor that can fly and increase speed. The problem is when the actor's velocity gets fast enough the projectile gets left behind and eventually collides with the actor. Does anyone know how to make the projectile have an initial velocity which is relative to how fast the owner actor is at the time of firing? I've tried exposing a projectile velocity parameter from the projectile BP and then setting it to the sum of the velocity of the actor and a constant vector. It works sometimes but when I face other directions the projectile becomes really slow.
Announcement
Collapse
No announcement yet.
Set projectile velocity relative to owner actor velocity
Collapse
X
-
Originally posted by Bluarchon View PostI'm able to fire projectiles fine from an actor that can fly and increase speed. The problem is when the actor's velocity gets fast enough the projectile gets left behind and eventually collides with the actor. Does anyone know how to make the projectile have an initial velocity which is relative to how fast the owner actor is at the time of firing? I've tried exposing a projectile velocity parameter from the projectile BP and then setting it to the sum of the velocity of the actor and a constant vector. It works sometimes but when I face other directions the projectile becomes really slow.
This is my solution, inside my gun's BP, where a spaceship's velocity is added to the bullet's (it has a default speed given to it by the gun that fires it). You can ignore the nodes on the left - that was just me getting the gun's root, then the ship that the gun is attached to, so I can use its velocity. 'Projectile Speed' is just a property inside the gun that dictates the default speed of bullets, ignoring velocity, but it's only a float, so I make a vector with it as the X component. This works for any direction because I use the ship's transform matrix to rotate the vector so it's local/relative to the ship.
Let me know if this works for you.
-
Originally posted by Bluarchon View PostHmm. I can't seem to find the Rotate Vector by Transform node whether I pull out a transform wire or a vector wire. I've UE 4.3.0.
If you're interested, here is how I set up the custom node in C++:
In CustomNodes.h:
Code:#pragma once #include "EdGraph/EdGraphNode.h" #include "CustomNodes.generated.h" /** * */ UCLASS() class UCustomNodes : public UEdGraphNode { GENERATED_UCLASS_BODY() UFUNCTION(BlueprintPure, meta = (FriendlyName = "Rotate Vector By Transform", Keywords = "rotate vector transform", Category = Maths)) static FVector RotateVectorByTransform(FTransform InTransform, FVector InVector); };
Code:#include "FlightPrototype.h" #include "CustomNodes.h" UCustomNodes::UCustomNodes(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP) { } FVector UCustomNodes::RotateVectorByTransform(FTransform InTransform, FVector InVector) { FQuat Rotation = InTransform.GetRotation(); return Rotation.RotateVector(InVector); }
Comment
Comment