How can i make this effect?

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

I want my weapon sprite to have a movement like this. I tried to do it but i didn’t make it. How can i do it?

btw here is my gun code:

extends Control

onready var anim_player = $AnimationPlayer

var can_shoot = true

# Weapon sway
var MoveAmount = .5
var MoveSpeed = 20

var _origin = rect_position

func _ready():
	anim_player.play("idle")

func _physics_process(delta):
	if Input.is_action_pressed("shoot") and can_shoot:
		anim_player.play("shoot")

	var mouse_position = get_viewport().get_mouse_position()
	
	var moveOnX = mouse_position.x * MoveAmount
	var moveOnY = mouse_position.y * MoveAmount
	
	var newPos = Vector2(moveOnX, _origin.y + moveOnY)
	
	_origin = lerp(_origin, newPos, MoveSpeed)

What effect are you talking about? A weapon (and the appendage to which it is attached) being affected by the motion of the player’s movements? Maybe this video from Garbaj would help?

Ertain | 2022-09-18 18:49

it workedddddddddd thxxxxx!!!11!1

harden32x | 2022-09-18 19:36