0 votes

I am currently creating a top down game for my first project and the character is moving equally to global mouse position. How can I move the mouse back (basically a knock-back effect) every time the player will get hurt as an indication of getting damage? Thank you and sorry for my bad English, I do hope I managed to get my point across.

Godot version 3.2.3
in Engine by (15 points)

1 Answer

+1 vote
Best answer

Try using Viewport.warp_mouse().

# at top of script
const KNOCKBACK = Vector2(-20, -20) # or some other value
# in function somewhere
get_viewport().warp_mouse(get_global_mouse_position() - KNOCKBACK)
by (8,528 points)
selected by

Hey thank you so much! I got it to work! I will search if I can make it to work together with the angle of how the mouse approaches the trap/obstacle. Have a good one!

This is the effect by the way for those who are wondering:

enter image description here

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.