x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Forward Vector Points in Wrong Direction

Okay, so I'm trying to do line traces in a third-person 3D game (UE 4.8.3) using forward, up and right vectors but none of them actually point forward, up or right relative to the actor. They all point at the same absolute world location (no matter the actor rotation), rather than a location that's relative to the character's rotation or location. I'm assuming that it's the world origin but I'm not sure. (When I follow the direction of the line traces with my character and get to the world location it's pointing to, it starts pointing straight downward.)

I've tried using GetActorForwardVector, as well as using GetForwardVector on the Capsule Component and the character mesh and other components parented to my character but all of those result in the same wrong direction. I've also checked whether my Capsule Component, for whatever reason, might not be rotating with the character but it is and I'm kind of at my wit's end. Am I using these vectors wrongly or making some stupid mistake? Is this a bug? I have no idea. I'm almost certain that I've used forward vectors before in exactly this way and it worked fine.

This is my Movement Input Blueprint. I've taken out some of the clutter but even with this simplified setup I still get the results mentioned above. (I've disabled the TurnRate and LookUpRate inputs as my camera is supposed to be locked behind the character): MovementInputBP

This is the line trace setup I'm using to test the error. I'm using the world location of EdgeCheck (which is a capsule attached to my character) because, otherwise, it'd just draw the line in the world origin, which appears to be beneath the floor, as opposed to from the character to the world origin. So we wouldn't even be seeing the line at all: LineTraceBP

And this is what the line trace looks like in-game. The character is rotated differently in each of the images but still the line trace always goes into exactly the same absolute direction: LineTraceIngame

I've also found this old thread which appears to be talking about either the same or at least a similar problem but it looks like it was assumed that that was just a bug from the beta version so it got closed. Still, I think it doesn't hurt to link it here just in case:

https/answers.unrealengine.com/questions/11969/do-a-line-trace-in-character-facing-direction-blue.html

Product Version: UE 4.8
Tags:
more ▼

asked Aug 19 '15 at 03:32 AM in Blueprint Scripting

avatar image

FrozenHarlequin
13 4 4 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Yes, it's doing exactly what you want it to do in your nodes. You aren't projecting the line trace. Really, all you need to do in order to get your current setup to work is from the forward vector, add your trace distance to the X and then plug it in. This still may not project correctly depending on how you have your vectors setup on your character though. A transform direction node may be needed but attempt what I mentioned above and if it's still not going "forward" exactly how you are facing each time then I will help you solve it further, but the aforementioned should give you a horizontal trace regardless.

alt text

5000 in the add vector node is an arbitrary number. Put in there how ever many units you want the trace to go.

Hope this helps! If so, I would appreciate it if you could accept the answer by clicking the check mark located under the arrow keys next to the answer. When done correctly, the answer will highlight green! Any other questions just let me know.

EDIT: To expand on why your current setup isn't working like you expect. What you are doing is getting the world location of your "Edge Check" variable, which you say is your capsule and setting that as your "Start" location for the trace. Then, you simply plug in the Forward Vector of you character as the "End" location. Therefore, it simply draws a trace from your Capsule to the center of your mesh. Use the nodes as I have setup in the picture and you should be golden!

trace.png (98.8 kB)
more ▼

answered Aug 19 '15 at 04:31 AM

avatar image

jtsmith
1.4k 70 29 92

avatar image FrozenHarlequin Aug 19 '15 at 04:50 AM

Hi, thanks for the reply. Unfortunately, that doesn't solve it. Getting the forward vector of the actor rotation doesn't change anything, adding the 5000 does change the direction of the line trace but it's still pointing towards an absolute position and the actor rotation has absolutely no effect on its direction.

avatar image jtsmith Aug 19 '15 at 04:52 AM

so the line trace is now a horizontal (forward facing) trace only it's going in an incorrect path?

avatar image FrozenHarlequin Aug 19 '15 at 04:59 AM

It is horizontal, as opposed to facing downwards, yes. That's the only thing that's changed from what I've described in the original post, though :/.

avatar image jtsmith Aug 19 '15 at 05:21 AM

I can't tell from here how you have your controller setup. My controller is setup so that when I press "W" my character moves forward but is using a "Transform Direction" meaning that whatever way I'm facing is considered X axis. What I believe is happening to you is using the "Get Actor Rotation" as I showed above is giving you the rotation of your root component which apparently seems to not be rotating properly with your mesh. Your line trace seems to be either following the rotation of the root component or it is always following the world X axis but again, I can't see that from here ;)

One problem may be that the "face" of your character is not properly facing the capsule direction (indicated by the red arrow in the viewport.) This may not be the case but worth checking since your capsule/root component should always be rotating equally with the child mesh. Another thing worth checking is what you are actually rotating when you turn your character. If you are rotating the mesh specifically then the root component (capsule) will not rotate with the mesh but if you are rotating the actual pawn/character then the capsule is being rotated by default and therefore rotating your mesh (assuming your mesh is a child of the capsule.)

If your camera is always facing the direction your mesh is headed, in other words you can't rotate the camera around to see the side or face of your character without the character moving, then try the node "Get Control Rotation" in place of "Get Actor Rotation" which will give you the rotation of the controller, which is often the "view" of the camera.

avatar image jtsmith Aug 19 '15 at 05:33 AM

Here are 2 other options for you... The first one is what I mentioned above, using the "Get Control Rotation"

alt text

The next one is another alternative. Where you see "Sphere" that is actually my pawn/character mesh. Drag/drop your mesh (not the capsule) into the Event Graph, plug that into "Get World Rotation" and then plug that into the "Get Forward Vector"

alt text

trace2.png (75.7 kB)
trace3.png (81.0 kB)
avatar image FrozenHarlequin Aug 19 '15 at 05:40 AM

I've printed the rotation of the CapsuleComponent's world rotation (the CapsuleComponent is my character's root component). It does change when I rotate the character and the yaw value appears to be moving in between -180 to +180 (with pitch and roll both being 0). I've also tried printing out the Capsule Component's forward vector whose X and Y values are between -1 and +1 (Z is 0), same with the ActorForwardVector.

Changing ActorRotation to ControlRotation doesn't change anything, unfortunately.

avatar image FrozenHarlequin Aug 19 '15 at 05:57 AM

Sorry, I only saw that second comment now. Using the Mesh's world rotation doesn't work, either. It gives me the same result as before.

avatar image jtsmith Aug 19 '15 at 07:10 AM

I'm not sure what else I can think of that would be the problem. There's obviously something going on inside your code because the examples I gave above work for me. Only suggestion I have, assuming you don't find the answer elsewhere any time soon, would be to upload your project to Dropbox and let me, or someone else knowledgeable enough, take a look at it and see what we can find. If this isn't an option (I'm usually protective of my stuff too) then I'm not sure of anything else I can do short of you posting a ton of screen shots of your code. If I don't hear from you again, good luck with solving this!

avatar image FrozenHarlequin Aug 19 '15 at 08:42 AM

I've deleted almost everything from my blueprint except for the two parts I posted a screenshot of in the first post (in a copy of my project, of course), reset everything in the pawn to its default values and even deleted most of my animation blueprint but that hasn't fixed the vector directions, either. Still, thank you so much for your help and I'll definitely think about uploading my project :).

avatar image jtsmith Aug 19 '15 at 09:46 AM

If I get some time in the morning I will create a blank project myself and attempt to replicate this for you. And you are welcome.

avatar image FrozenHarlequin Aug 21 '15 at 05:34 AM

Okay, now I feel stupid for not trying that myself. I've now tried it and it looks like the problem is my movement input setup. More specifically, the fact that I add the Axis Value from the MoveRight Input to the Controller Yaw Input. But I don't know how else to set up the character movement so it's camera-independent (while still giving me the option to change the camera position or use fixed camera angles in certain situations, etc). Should I open a new question for that and mark this one as answered?

EDIT: Or is this unexpected behaviour for the AddControllerYawInput node?

avatar image jtsmith Aug 22 '15 at 10:48 AM

Can you post a screenshot of how your movement input is currently set up? I may be able to help diagnose in this thread without you posting another question.

avatar image FrozenHarlequin Aug 22 '15 at 10:57 AM

It's the first screenshot in my original post.

avatar image jtsmith Aug 22 '15 at 11:06 AM

I think the problem may be that you are focusing on world direction. Watch this video I just did the other day and although my needs are different than yours, it should help you figure out another and possibly better way to setup your movements. I only show the "forward" movement in this video but the left/right will be similar in nature. I'll probably have the video for the lateral movements up in a few days if you need to see that one but this one should help regardless.

https://youtu.be/MpKXKr9alqY

PS did you make that rat character yourself?

avatar image FrozenHarlequin Aug 22 '15 at 12:47 PM

Thanks for the link, that was an interesting tutorial. I've tried using the Transform Direction node (with a simple (1,0,0) vector, the ActorForwardVector and the ControlRotation's forward vector - not all at once, of course :p) and plugging that into the AddMovementInput's WorldDirection pin but that didn't solve it, either. I've also tried replicating your setup and using SetActorTransform for movement and rotation but I can't seem to get rotations working with it (no matter what I plug into the new transform's Rotation pin, the character never rotates). When I try only using SetActorTransform for the forward movement (and AddControllerYawInput for rotations) I'm back to my old problem of the forward vector not working correctly.

PS: Yeah, I made that myself :). However, I suck at rigging so the skin weights are all messed up :p.

avatar image jtsmith Aug 23 '15 at 07:54 AM

Alright brotha, I got this figured out for you! I spent some time working on it but realized the answer was staring me/us right in the face. Need the Actor rotation as well as the forward vector but the forward vector is normalized meaning it's a float value. This should work for you!

alt text alt text

Also, the 5000 is an arbitrary number, insert the number for however far you want the trace to go. Also, if you don't want the trace to extend from the pivot point of your mesh, add an offset vector variable which raises the trace up the Z axis a bit but if you aren't shooting projectiles and only using this for your character to run like a rat in a maze :) then center pivot should be ok but if you need, let's say, head clearance then make an offset that is as high, or slightly higher, than your meshes head.

forwardtrace.png (132.9 kB)
avatar image FrozenHarlequin Aug 23 '15 at 09:58 AM

That did it! Thank you SO much!

avatar image Nerdballer Games Sep 07 '17 at 11:31 AM

There it is!

avatar image FrancoACT Oct 18 '18 at 10:21 PM

Thanks so much! I've been 3 hours with this problem and this was the solution.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question