This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hey everyone! Beginner to gamedev in general over here.
I chose a shooting gallery asset pack at random and decided to make a tiny game with it.
I want to stretch, squash, and pivot the rifle to the position of a position2D node that is further down the hierarchy (which follows the mouse whenever a MouseMoveEvent is triggered), does anyone have any useful / relevant links that I might use?

in Engine by (27 points)

Is the rifle a sprite? Do you intend to rotate the sprite around a fixed point? If so, you can use the look_at() function (or some similar code) to move the sprite around. To squash and stretch the sprite, change the "size" property of the sprite's image. Change the size with respect to how far/close the mouse is from the rifle. Use some ratio (such as the position of the mouse and the rifle image) to scale the sprite with the mouse.

Thanks! I did end up changing the scale of the sprite in relation to the mouse position.

1 Answer

+1 vote
Best answer

If you're talking about a sprite like this one:

https://toppng.com/image-fps-gun-sprite-sheet-PNG-free-PNG-Images_215407

What I would do at a high level is to figure out the vector the gun points along and then use that with the vector you want it to be pointing to to figure out what transforms you need to apply to the sprite. It will take some tweaking and figuring out which transforms look best (stretching height vs stretching width, etc)

If it's a simple top-down sprite then look_at() is something you should look up in the docs.

by (134 points)
selected by

Thanks! You hit the nail on the head, I ended up subtracting the mouse position from the InputEventMouseMotion from the Sprite's origin position, adding it to the horizontal scale of the Sprite --with some stops so that it doesn't stretch too far either way, of course--.
For vertical motion I think I'm gonna go with a slight rotation in the general vertical position of the event, but I still got to implement it.

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.