problems with rotation

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By gm130993

I’m trying to make a bullet hell game and i need a gun to rotate based on the mouse position and flip when it’s rotation is between 90° and 270°, however i’m currently facing two problems:

first, i can’t get the gun to flip based on the rotation and it is rotating from the middle instead of having the grip as the center for the rotation

how can i solve these problems?

note: idk if this changes anything but the gun is a child node of the player

:bust_in_silhouette: Reply From: chaosgaming

Try this:

store the grip position as a variable as such
export var gripPos = grip.position

then store the rotation
export var bulletRot = grip.rotation / or whatever you are trying to get the rotation of

then in the root node
make sure you have your bullet scene loaded
var bullet = preload("put the location of your bullet in res here ").instance()

add_child(bullet)
and then set the rotation and position of the bullet

for flipping try checking the rotation and if say rot > 90 += certain number or try inverting the number by using something like * -1

:bust_in_silhouette: Reply From: rossunger

Sprite2d has a flip_h property and an offset property which should accomplish what you’re trying to do.

The offset will define the the point around which the sprite will rotate.

i did use flip_h but it doesn’t work based on the degrees of the rotation, though it worked when it was based on a input

gm130993 | 2022-02-15 00:24