#Is there a way to change the global mouse position?

45 messages · Page 1 of 1 (latest)

velvet coyote
#

My player looks at the mouse position with look_at(get_global_mouse_position()). I want the player to look for example 45 degrees from where it was originally looking at when it pressed the spacebar

#

Is there a way to change the global mouse position?

vagrant spoke
#

Can you show code??

velvet coyote
# vagrant spoke Can you show code??

Here is my player's movement code:

func _physics_process(_delta):
    if !ui.inventory_open:
        velocity = Input.get_vector("move_left", "move_right", "move_up", "move_down").normalized() * move_speed
        velocity += extra_velocity
        move_and_slide()
    
    look_at(get_global_mouse_position())
vagrant spoke
#

you can use

#

Rotation=rotation+PI/4*delta

#

Write lie this

#

If input.is_action_pressed("spacebar")

#

Rotation=Rotation+PI/4*delta

#

Notify me if that helped

velvet coyote
#

nope..

vagrant spoke
#

Well i think you the look at() fuction is interupting it

#

So i think you can write

#

Look at(get_global_mouse_position+new_rotation)

#

Declare a variable

#

Var new_rotation:float=0.0

#

Then in physics process write

#

If input.is_action_just_pressed("space_bar")

#

New_rotation=pi/4

vagrant spoke
#

So does it helped??

velvet coyote
#

trying right now

#

look_at(get_global_mouse_position() + new_rotation) throws an error: Invalid operands 'Vector2' and 'float' in operator '+'.

vagrant spoke
#

So it is vector 2

#

I think you can write var new_rotation:vector2=vector2(0.7071,0.7071)

#

And try to add it now

velvet coyote
vagrant spoke
velvet coyote
velvet coyote
#

didnt rotate :(

vagrant spoke
#

Well i think i have run out of ideas

#

This time

velvet coyote
#

alright..

mild stump
#

Hi @velvet coyote i was hoping to try to help. So is the idea that you don't want to physically offset the user's mouse right? its just you want access to a 45 degree offset from where the player's global mouse position currently is at any given time?

velvet coyote
#

sorry, i don't get what you mean 😅 buut basically i want to change the mouse position such that its 45 degrees from the previous mouse position

#

so when i press spacebar it changes

mild stump
#

so move the user's actual mouse cursor position? for that we do have the warp_mouse(Vector2: position) method that is a method Viewport has where you pass it a Vector2 and it will warp the mouse to that position. Not sure if that would be useful to you here?

velvet coyote
mild stump
#

I go into it with this video a bit