How to make the "sway" effect on weapons of FPS 3D games

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

I recently started in godot and I am learning very well but now i’m stuck in this problem.

Sway effecto in HL

I want to make this effect on the weapons when the camera moves arround. I already saw a lot of videos and tutorials on how to do it in Unity but I can’t get the same result, or even make it work in Godot because it uses GDScript instead of C#.

I saw a video (Link : and I do not understand how he use the Transform. What little I have learned about Transforms can be enough to figurate out what is happening in that video.

I know the solution seems so simple in Unity but I tried everything in godot and i can get the answer, i even try messing with the Transform and i got weird effect like streching and deforming the Sword (My weapon is a sword). I read the documentation (of Godot and Unity) but i can’t get the nexus.I would like to post my code but I just erased it because I remade it arround 20 times.

Please if you can help me with or some documentation i can learn to make this or have an explanation I would appreciate it very much because this is one of a lot of barriers i will have in my project.


PD: sorry about my English Speaking, I’m Chilean

You may be able to pull this off with vectors and animations. Have code which detects the vector of the character’s movement (or you could even detect it by monitoring the “x” value on the motion vector). When the character moves in one direction, have the animation blend to the gun swaying in the opposite direction (either via a Transition or a Blend2 in an AnimationTree).

Ertain | 2020-04-27 06:57

I’m trying this and actually looks less complicated than transforms. I am doing some experiment with the AnimationTree and I see that the result is promising. I also get inspired by this video of Wolfire Games with the Overgrowth Procedural IK system (Link to the video) where the animator use just 13 frames for all the animation. He just interpolate that poses to fake the movement. I will try to do something similar . Thanks for answering!

Cvncer | 2020-04-28 04:57

:bust_in_silhouette: Reply From: zen3001

Modify the rotation of your weapon model with what ever vector you used to move arround the camera, here’s the script I’m

var m_move:Vector2
var move = false
var sensitivity

func _process(delta):
	if move:
		move = false
		#the -90 is only needed for the model I am using
		$Item.rotation_degrees.z = -(m_move.x)*delta*12
		$Item.rotation_degrees.y = -90+(m_move.y)*delta*10
		$Item.rotation_degrees.x = 0
		$Item.rotation_degrees.y = -90

func _input(event):
	if true:
		if event is InputEventMouseMotion:
			m_move = Vector2(clamp(event.relative.y, -sensitivity, sensitivity), clamp(event.relative.x, -sensitivity, sensitivity))
			move = true

The scene tree
|_FOV(script run from here)
instance what ever weapon model you have here

yeah, this only sways the rotation and it isn’t the smoothest but I’m sure you could get it to be a little smoother by just playing arround with the numbers a bit