Convert a trace location X rotation from World to Direction from the 1st point to 2nd

Basically, exactly what the title is. I’m trying to get the angle degrees of 2 points in a trace. but depending on my direction in world space. I will instead get the opposite results.

Meaning that a positive or incline angle will become negative instead of it’s clearly positive, since it is going up, or vice versa. But if I go in the opposite direction with the exact incline copied in the other way. It will be positive as it should be.

A very derpy example

Why is this happening? Well, it is because like if I took an arrow object in the editor using world space rotation, and 180 it. that is the forward direction but it’s -180 degrees or Upside down in the other way. making up, down and down, up.

An example showing what that all means

Great, I know why it’s happening, but I have no earthly Idea how to fix that…help…

Hey @KillerGerbil!

So X rotation (roll), yes, will invert up and down. If you want the values to not be negative, you can break that and set X to 0 in the angle after it’s computed, or even try taking the X float, making it ABSolute, and then making the vector again with that adjusted X value. Most characters, for instance, have X rotation locked because that’s the barrel roll rotation.

I hope this helps!

Sadly I’ve tried these solutions.

So for example, lets say I remove the X, well. it loses any direction that is Forward in terms of unreals understanding of world space. so I get weird numbers like -50 and 90 on flat ground. it just…Idk

I also don’t want ABS since they remove negatives. AKA declines.

I’ve also tried look at rotations, calculate directions with a varied of inputs from the trace results.

The numbers I get are the correct angles. it’s just being reversed if I go in the negative vector directions in world space. IE. -Y -X values. That’s where the flip happens

I’m sorry If I’m not giving too much information, I’m trying to feed as much as I need to, so I don’t bog people down with unnecessary information that just makes this complicated for no reason. That’s why I didn’t take a screen shot of the Blueprint.

And thanks for your help

Well, if you’re trying to get the angle degrees of two points in a trace… Negative in Y and X is just going to mean “West and South” (+Y= North | -Y = South | +X = West | -X = East |+Z = Up | -Z = Down). It’s somewhat intrinsic to direction that you’re going to get negatives. I know you’ve gone through a good strong try to explain the issue but maybe if we could get the context of what it is you’re trying to do in the game it could bridge the gap of understanding?

Ok I’m going to try and give a better explanation, because I feel like this is a “DUH” type solution or a “it’s actually just this node” type thing. But it’s a rare one that’s a “you’re in the know.”

If I approach an incline in the Positive World X, or West. It gives me a positive result.
If I approach an incline in the Negative World X, or East. It gives me negative result.
If I approach an incline in the Positive World Y, or North. It gives me a positive result.
If I approach an incline in the Negative World Y, or South. It gives me negative result.

Both of these are dealing with only inclines. Yet have very different returns based on their direction in world space.

Now…

If I approach an decline in the Positive World X, or West. It gives me a Positive result.
If I approach an decline in the Negative World X, or East. It gives me Negative result.
If I approach an decline in the positive World Y, or North. It gives me a Positive result.
If I approach an decline in the Negative World Y, or South. It gives me Negative result.

Now all of these are dealing with only declines.

All declines should be negative results.
All Inclines should be positive results.

See my issue?

The traces are irrelevant. it’s just getting the angle of up and down between the two points.

0 is flat.
- is down
+ is up

In some directions in world space it gets it, but that’s because it’s in world space. not the direction to get to point 2 from point 1

the “location” from “break hit result” is in world space.

Quote

Location of the hit In world space.

Other outputs or vectors don’t give the desired result by just plugging and playing with them.

The point of this system is to get the direction the actor is going compared to where they have been.

Ahhhhhhh hold on. DO post the code. Because I think I may have the answer for you!

It all depends on DIRECTION. So the Z is the flipping issue, when the forward is -X or -Y, right? What if it’s -X AND -Y? Because we can fix this with booleans! We just need to know what happens to the Z if:

-X, +Y
+X, -Y
-X, -Y

Because basically, if it’s going to get flipped, you’ll MULTIPLY the Z by -1 (to re-invert it) if it’s going to be inverted! If we can get the cause in concrete we can solve it.

Ok, see this, this is a mess

It just has a lot of stuff that has NOTHING to do with this problem like Floor normal variables, they have no effect on the math.

I’ve been ripping it apart so much that I haven’t even bothered to clean it since I break it 5 seconds later…Programming


This is how it is detecting the angles from floor point to the 2nd point.

Both are locations from a trace Meaning both are in world space.

How many inclines do you have in your level of varying cardinal directions?

I noticed you’re using calculate direction. That returns a float, a single value of Z rotation, basically, and Calculate direction is based on the CURRENT forward direction. Usually this is used for a blendspace to calculate direction for movement animations.

A vector is just a set of 3 coordinates. If you want the angle of just the X, Y, or Z, do your lookat node as you’re already doing, right-click, break pin, and take the given value of X, Y, or Z and there’s your angle :slight_smile: you don’t need that calculate direction node, I’m almost certain that’s throwing a wrench in your code!

Remember when I said “duh”

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.