0 votes

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 : https://www.youtube.com/watch?v=hifCUD3dATs&t=569s) 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.

Cheers.

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

in Engine by (12 points)

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).

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!

1 Answer

+1 vote

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
    else:
        $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
KinematicBody
|Collisionshape
|
FOV(script run from here)
....|Camera
....|
Item
........|_*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

by (253 points)
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 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 webmaster@godotengine.org with your username.