The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

Hi! I'm making a game (of course), and I have a question. Essentially, the player has a "fist" that rotates towards the mouse (i have no problem with this part, it's the next part I need help with), and when the player clicks, I want the player to move towards the direction that the "fist" was facing (not necessarily towards the position where the mouse was when it was clicked - if the user clicks nearby the player, I want the player to move in the direction of the mouse and keep going even after it has passed where the mouse was when clicked).

in Engine by (125 points)

1 Answer

0 votes

I think you could achieve this by using xform function and passing it a vector like Vector3(0,0,-1) (assuming you are in 3D space, Vector2 if you are in 2D).

The idea here is, that xformwill get the movement relative to the node, where -z axis is forward, and then return coordinates in global space, which you can use for movement, for example with move_and_slide() or setting linear_velocity of a rigid body.

I use this technique to fire a bolt from a crossbow, held by the character and the bolt should be fired in the current direction the crossbow is pointing, not towards mouse or player.

by (207 points)
edited by
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.