Download

What's the best way to convert from degrees to FVector?

I’m working on a 2D game and I am looking for a solution that allows me to set a degrees value in the editor under the pawn attributes so that it can get spit out in a formula that defines the impulse of the object as it ticks.

I’m using twinStickShooter as my basis, and I already understand how to define a UPROPERTY to get it editable in the editor. I’m just kind of tangled up in FVectors, Rotators, FRotators etc All I know is I need an FVector to feed to the impulse.

Any insight would be much appreciated! Thx!

An impulse is a short force push in a direction, so it obviously needs to be a vector. The direction of the vector is the direction of the force and its length is the amount of force added. Could you explain in a little more detail what you are trying to do? Are you attempting to add an impulse in a certain plane only (xy-Plane, i.e. on the ground?) and want to define the direction by an angle from a certain axis and the magnitude in a different variable? If so, the components would be


FVector(FMath::Cos(FMath::DegreesToRadians(degree)), FMath::Sin(FMath::DegreesToRadians(degree)), 0)*magnitude

Hey thanks for replying. Ok that makes sense. I was just having issues working through the spaghetti of calling so many functions inside FVector and I wasn’t sure if I was supposed to be using FRotator to store the degrees (looks like that’s a no!).

So essentially I could make float vars to fill in for ‘degree’ in your example. Ok that’s great, thank you!

Alright, now for a truly noob question that is related:
Why is this legit…
(inside implemented function in cpp)


const FVector MovementDirScratchVec;
blahblah execution stuff blahblah
FVector MovementDirScratchVec(DegreesOnXYToFVector(FlapLeftDegrees)); 

But not this…


const FVector MovementDirScratchVec;
blahblah execution stuff blahblah
MovementDirScratchVec(DegreesOnXYToFVector(FlapLeftDegrees));
Nor could I replace the above with this:
MovementDirScratchVec = DegreesOnXYToFVector(FlapLeftDegrees));

Thanks again!

Ah I got it after playing around a bit. So FVector objects always need the FVector type in front of any FVector data being moved around?
ie:


MovementDirScratchVec = FVector(DegreesOnXYToFVector(FlapLeftDegrees));