control the character with the mouse

Hello, I can’t solve the problem with pawn control. The task is to control a pawn in a certain area using the mouse. Control using the keys made everything work. but I can’t correctly convert the mouse position into global coordinates and relate it to the movement of the pawn.

Could you clarify what is needed? You want to move the pawn to where you click?

I have a rectangular playing field and at the bottom I added a pawn object, and I need the player to control this object with the mouse. a game in the style of Rebound Ball where you need to hit the ball to destroy all the objects at the top of the field. I set up control with help ( W,S,A,D) but I didn’t like it and wanted to make a movement with the mouse

So an arkanoid…?

Arkanoid

And you need to move the paddle left <> right with the mouse?

the genre is similar, but you also need control along the X axis so that it is possible to move along the Y and X axis in a certain limited field. Because of this, I want to convert key control to mouse control

  • standard input:

image

image

  • a pawn with a collider at the root + floating movement component:

Play with the Floating Movement Component settings, flip the axis to fit your needs. Perhaps add a nicer custom curve to the Enhanced Input. You can restrict the boundaries with meshes or collision boxes.

Looks like it could work fine-ish once tweaked:

what control(blueprint class player controller) are you using? and when you create a new controller, do you need to enter all the movement logic there?
what you wrote doesn’t work for me, maybe I’m doing something wrong

This is a blank project. There is no controller here (default one). The movement is in the Pawn - the paddle, in the pic. Tried to keep it minimalistic.

Using the XY value of the input axis event works fine for mouse. Other hardware in particular joysticks might drift by a small factor each frame but this can be filtered out by ignoring low values. This is irrelevant since the topic is for a mouse but if this is your wish:

then you could also consider using this instead for your cursor position, to deproject from 2D to 3D world space:

UGameplayStatics::DeprojectScreenToWorld

OP wanted mouse controls specifically. Besides that, EI handles drift natively - via deadzones.

Admittedly, there’s more than one way to set this up! This was the first thing that came to mind.

1 Like

I am aware, and your solution looks good. Deprojection is common when you want to get a position under the cursor (3D). Input axis is common when you just want to register left / right movement which seems to be the case here. I mentioned deprojection specifically because the question mentioned mouse to coordinate conversion. deprojection might give a more natural feeling if the movement speed matches the mouse speed you are used to, but it’s up to preference. If the game is going to be controlled with both WASD and the mouse, you optimally want to provide the same experience for both to not give an advantage with one or the other. Snapping the movement to mouse position would give a large advantage over wasd movement in which case you might consider not using deprojection.

I unknowingly recorded everything in blueprint (blueprint class player controller) now I’ll try another method

Does not really matter where controls, controller is more than good. So is Pawn, at least here.

Oh btw! Totally offtopic but for this type of game I got something cool. I used these calculations in a SHMUP game to control how I keep objects within screen area without the need for blocking collisions. It feels really smooth. I felt the need for this because I didn’t want to “box in” the entire level design, I could just let objects fly in and tell them to stay in the camera area bouncing or gliding at the edges. Anyway, more people can enjoy it:

Math question. finding distance to the edge of a plane in direction from center. - #16 by Roy_Wierer.Seda145

1 Like

To answer more directly:

The above is pretty agnostic, it, kind of, looks like this:

You project the mouse screen-coords into the 3d world and eventually intersect a virtual plane at the specified depth (where the paddle is). You can use this coordinate to move the paddle.

It’s a pretty decent method. This way you can eliminate movement input and the pawn’s movement component, make things more responsive; but now you must find a decent collision solution. You could manually clamp it and that could work, too.

How to approach it all really depends on the must have features, desired behaviour, the overall feel and so on.

I am going to shamelessly copy this and use it for displaying screen edge indicators. What a gem of a thread.

1 Like

everything worked out, maybe there were problems in the old project

1 Like

Can you recommend any good tutorials for learning blueprint?

Any good documentation of the structure, architecture, and internals of Unreal Engine? - #2 by Roy_Wierer.Seda145

Links at the bottom most relevant to BP, Mathew Wadstein and Freya Holmer on youtube.

Thanks a lot!