+1 vote

When I press "aim" it does not update the animation on my BlendSpace2D. I am trying to put this to work 2 days... Please, send help!!!!enter image description here

``
extends KinematicBody

var direction = Vector3.FORWARD
var velocity = Vector3.ZERO

onready var anim = $AnimationPlayer

var vertical_velocity = 0
var gravity = 20

var movementspeed = 0
var walk
speed = 3
var runspeed = 8
var acceleration = 5
var angular
acceleration = 7

var strafe = Vector3.ZERO
var strafe_dir = Vector3.ZERO

var aim_turn = 0

func input(event):
if event is InputEventMouseMotion:
aim
turn = -event.relative.x * 0.015

func physicsprocess(delta):

if Input.is_action_pressed("aim"):
    $AnimationTree.set("parameters/aim_transition/current", 0)
else:
    $AnimationTree.set("parameters/aim_transition/current", 1)

var h_rot = $Camroot/h.global_transform.basis.get_euler().y

if Input.is_action_pressed("move_fw") || Input.is_action_pressed("move_bw") || Input.is_action_pressed("move_left") || Input.is_action_pressed("move_right"):

    direction = Vector3(Input.get_action_strength("move_left") - Input.get_action_strength("move_right"),
                0,
                Input.get_action_strength("move_fw") - Input.get_action_strength("move_bw"))

    strafe_dir = direction

    direction = direction.rotated(Vector3.UP, h_rot).normalized()

    if Input.is_action_pressed("sprint") && $AnimationTree.get("parameters/aim_transition/current") == 1:

        movement_speed = run_speed
        $AnimationTree.set("parameters/iwr_blend/blend_amount", lerp($AnimationTree.get("parameters/iwr_blend/blend_amount"), 1, delta * acceleration))

    else:
        $AnimationTree.set("parameters/iwr_blend/blend_amount", lerp($AnimationTree.get("parameters/iwr_blend/blend_amount"), 0, delta * acceleration))
        movement_speed = walk_speed
        strafe_dir = Vector3.ZERO


else:
    $AnimationTree.set("parameters/iwr_blend/blend_amount", lerp($AnimationTree.get("parameters/iwr_blend/blend_amount"), -1, delta * acceleration))
    movement_speed = 0

if $AnimationTree.get("parameters/aim_transition/current") == 0:
    direction = $Camroot/h.global_transform.basis.z

velocity = lerp(velocity, direction * movement_speed, delta * acceleration)

move_and_slide(velocity + Vector3.DOWN * vertical_velocity, Vector3.UP)

if !is_on_floor():
    vertical_velocity += gravity * delta
else:
    vertical_velocity = 0

if $AnimationTree.get("parameters/aim_transition/current") == 1:
    $Mesh.rotation.y = lerp_angle($Mesh.rotation.y, atan2(direction.x, direction.z), delta * angular_acceleration)
else:
    $Mesh.rotation.y = lerp_angle($Mesh.rotation.y, h_rot, delta * angular_acceleration)

strafe = lerp(strafe, strafe_dir + Vector3.RIGHT * aim_turn, delta * acceleration)
$AnimationTree.set("parameters/strafe/blend_position", Vector2(-strafe.x, strafe.z))

aim_turn = 0

´´

in Engine by (25 points)

1 Answer

+1 vote

You code is formatted pretty bad but I think you're looking for something like this.

sprite.flip_h = event.relative.x < 0
by (109 points)

to fix the formatting, all you need to do is select all the code, and press the {} icon. =)

Isn't my post, so I can't format it.

I know, I was talking to Jm4rcos, I just posted the comment here because it was relevant to your answer. =)

Thanks but im using 3d

could you explain what behavior you are trying to get?

My 3rd person player walks and faces the direction of movement but when i click aim, it walks only forward and doesnt play the animation

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.

Categories