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.
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!
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):
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:
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:
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:
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.
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.
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”
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.
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!
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 :).
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?
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.
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.
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.
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!
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.