But this isn’t ideal as it is tracing for objects under the cursor, as opposed to using the actual screen location of the cursor.
As you can see in this video, with my mouse held still, the character snaps to different rotations when i move under an object and back out again.
[video]- YouTube
Unfortunately, neither of those are really ideal.
The first one, Every single object used as floor would need to be tagged. What about when the cursor is over a wall, or an object? The player will just face 0,0,0.
And the second one isn’t ideal as the game will be 3D. You will be able to move up and down all the time.
The only way to make it work is to have the player face the position of the cursor on screen. As opposed to any objects in the scene. That just doesn’t make sense to me. It just doesn’t work either.
I need to get the mouse location in screen space and get some kind of usable information from that to rotate the character.
Could you not break the World Location and World Direction from ConvertMouseLocationToWorldSpace, split the Start & End on the LineTraceByChannel, then only drag in the X & Y values?
If you really want a quick and dirty solution, use the line intersection method. Instead of using floor’s position as the Plane Origin, use your character’s position instead. Anyway, whether the player goes up and down does not matter, get the coords that you need.
To be honest, you will be limiting yourself if you take the easy way here. I still suggest you use the object channels. It’s a tad more work but you will be able to obtain more information about your world this way, especially at a later stage. And no, you do not need to ‘tag’ everything - not by hand at least. If your levels are going to me made out of modular pieces, you can have a class with the desired settings and instantiate, in the editor or during run-time, swapping meshes and materials as needed.
I don’t suppose you could go into more detail. I think I understand what you are suggesting. But I’m not sure how to go about setting it up.
Based on your previous advice. This is what I have set up so far.
It sort of works. The camera doesn’t jolt if the cursor moves over an object. But the character doesn’t seem to face where the cursor is located.
Scratch that. I was being dim. I used the character location as the input for the “Find Look at Rotation” “Start”. And it seems to be working brilliantly.
Old thread, but just wanted to share it helped me but I can suggest a further improvement.
When creating the upright plane, set the plane’s origin to the location of your weapon. This way the line projected to the mouse position will be from the barrel of the gun and shots will go perfectly where the cursor is.
If you use the character’s location the shots will always go above your cursor.