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.
Hi Bluarchon,
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.
Ah rotating the vector is what I’ve been missing. Thanks I’ll try this out as soon as possible.
Hmm. 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.
Ahh really sorry there, Bluarchon! Turns out that’s a node I wrote myself. You should be able to rotate it using a rotator, I think. Try grabbing the object’s rotation, and see if that rotation has a ‘rotate vector’ node.
If you’re interested, here is how I set up the custom node in C++:
In CustomNodes.h:
#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);
};
In CustomNodes.cpp:
#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);
}
Yes in the end I tried using the actor’s rotation and that worked for me. In any case what you posted would be really useful as well if ever I need to create custom nodes. Thanks again.