Hi guys, I’m making a prototype of the top-down shooter and I managed to get my character to move correctly and turn towards the mouse pointer. Now I want the player to have more vision where the mouse cursor is pointing, causing the camera to be placed between the player and the cursor. How can I achieve this with plans?
looking in YT I found these videos that serve as an example of what I want to implement
Hey, Dyon.
You’re going to want to get the camera and mouse locations, remove the up axis, then get the direction vector and vector length. After that you want to move your camera to a point somewhere along that direction vector, you can easily set it to halfway through by dividing the vector length you got earlier by 2 and make that run from an Event Tick.
Some of those nodes might be ActorLocation for you instead, since I used three boxes with different names for this mockup.
Hope this gives you a good starting point.
Cheers,
Dan
Dan thanks for your answer, but I have problems to get the location of the mouse
The most basic implementation would look like so:
Providing there is a camera attached to the springarm, this will place it between player’s cursor and the character. This is running on Tick in the character. Obviously this will benefit from a form of interpolation to smooth things out, basic camera lag might do; and a separate trace channel to ensure trace is hitting what it’s supposed to only - depends on how vertically designed your game is.
Everynone I did it as you say and the camera if it moves with the character and the mouse, but does not focus on the player, only where the mouse cursor points
It was just an example, not the final solution. It all depends on how you set it all up. Do note that I know *nothing *about your game. If you want the camera to inherit player movement and cursor position, you should feed it an offset in its local space.
edit: it seems to work well:
https://i.gyazo.com/b18355ca7a7c1e42…438c9238fb.mp4
Camera lag at low 2, it’s moved in relative space instead; make sure you set the Springarm Component’s transform’s location to Absolute Location
If you require something more advanced, you’ll need to provide more details.
That’s exactly what I’m trying to do! but I couldn’t make it with the code you provide
Show us how you scripted it.
I’m making a top-down shooter and have this code which is pretty similar to the one you make. It on a function.
I did your code to an event tick on the Event Graph. Change the spring arm to absolute location and it doesn’t work, the camera its all mess up. It appears that it send the camera far away.
You’re using to wrong node: *SetWorldLocation *vs *AddWorldOffset *- you’re flinging the camera who knows where
Man!!! I was trying to fix it for hours!!! you are a genius!!
Do you think there’s a way to restrict how much the mouse can go away from the player?
Thanks for all the help!
Like this maybe, I tested it very briefly, seems to work ok. You will need some kind of interpolation here, or at least camera lag set to something lowish - 5 or thereabout:
https://forums.unrealengine.com/core/image/gif;base64
edit:
I assumed you want to restrict camera movement rather than mouse cursor movement as this would be annoying for the end user.
Thank you!!! it works perfectly!!! that’s exactly what I wanted to do!!
This is exactly what I was looking for too, thanks so much!
The last screenshot seems to be lost though, could you maybe re-upload it for me Everynone?
If you still have it.
I don’t keep the screenshots for longer than 5 mins, and it’s been a year. What are we trying to do?
Like Fahr before me I’m trying to make my camera move between the player and the mouse.
I used the blueprint you posted earlier in this topic to make the springarm move on tick, that works great.
But I like to restrict how much the mouse can go away from the player (so the player doesn’t go off screen basicly). Do you have a suggestion?
It’s probably better done like this, you can punch in a value into the clamp node - that’s the max distance the springarm is allowed to travel from the actor.
The Springarm is set to Absolute Location and lag is set to 5. The function is running on Tick.
You can discard Z if peeking over obstacles is not needed. This can be also made completely geometry independent with Line Plane Intersection.
Thank you so much!
It works perfectly
I had a slight change of plans. I want to try setup an aim system that disregards height, or any geometry (basicly you just shoot straight from the gun, no pitch). I think that Line Plane Intersection you spoke of might be what I’m looking for.
I tried getting it to work myself, but didn’t get any favorable result.
I’m not sure how comprehensive it is, but if you could give me a pointer that would be greatly appreciated!
Try it like this:
Do tell how close it is to what you need.