K
K
K1ald2021-08-01 10:14:27
Unity
K1ald, 2021-08-01 10:14:27

How to make the cursor control so that the object chases the cursor?

For example, there are well-known games with screamers, you need to move the mouse around the screen and not touch the borders.
It is necessary to implement almost the same mechanics, only the cursor must be hidden, and instead of the cursor, the game object (character) should move.
Is there anything to suggest?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Misha_Unity, 2021-08-01
@Misha_Unity

The camera has a ScreenToWolrdPoint function that translates the cursor coordinates into world coordinates. Works only with orthogonal camera.

A
Alexey Fobius, 2021-08-02
@phobious

You take the coordinates of the cursor, and teleports the player to them, hide the cursor and here's your happiness.
I took the code from the cyberforum, it's not mine, the 1st link.

//Получаем координаты курсора
int CursorX = Cursor.Position.X;
int CursorY = Cursor.Position.Y;
 
textBox.Text = CursorX.ToString() + "   " + CursorY.ToString();
 
//Скрываем курсор
Cursor.Hide();
 
//Установка положения курсора
Cursor.Position = new Point(128, 128);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question