+1 vote

trying to get character animations to work and got help

http://www.godotengine.org/qa/1225/how-to-set-up-fps-animations

but i just can get it to work. i'm trying to modify a fps template.

https://github.com/Calinou/fps-test

i'm new to GDScripting and rusty at coding, this is what i have going on right now with the character.

extends RigidBody

var view_sensitivity = 0.3;
var should_play_anim = true

const walk_speed = 5;
const jump_speed = 3;
const max_accel = 0.02;
const air_accel = 0.1;

func _input(ie):
    if ie.type == InputEvent.MOUSE_MOTION:
        var yaw = rad2deg(get_node("body").get_rotation().y);
        var pitch = rad2deg(get_node("body/camera").get_rotation().x);

        yaw = fmod(yaw - ie.relative_x * view_sensitivity, 360);
        pitch = max(min(pitch - ie.relative_y * view_sensitivity, 90), -90);

        get_node("body").set_rotation(Vector3(0, deg2rad(yaw), 0));
        get_node("body/camera").set_rotation(Vector3(deg2rad(pitch), 0, 0));

func _integrate_forces(state):

    var aim = get_node("body").get_global_transform().basis;
    var direction = Vector3();

    if Input.is_key_pressed(KEY_W):
        direction -= aim[2];
    if Input.is_key_pressed(KEY_S):
        direction += aim[2];
    if Input.is_key_pressed(KEY_A):
        direction -= aim[0];
    if Input.is_key_pressed(KEY_D):
        direction += aim[0];
    direction = direction.normalized();

    var ray = get_node("ray");
    if ray.is_colliding():
        var up = state.get_total_gravity().normalized();
        var normal = ray.get_collision_normal();
        var floor_velocity = Vector3();

        var speed = walk_speed;
        var diff = floor_velocity + direction * walk_speed - state.get_linear_velocity();
        var vertdiff = aim[1] * diff.dot(aim[1]);
        diff -= vertdiff;
        diff = diff.normalized() * clamp(diff.length(), 0, max_accel / state.get_step());
        diff += vertdiff;
        apply_impulse(Vector3(), diff * get_mass());

        if Input.is_key_pressed(KEY_SPACE):
            #apply_impulse(Vector3(), normal * jump_speed * get_mass());
            apply_impulse(Vector3(), Vector3(0,1,0) * jump_speed * get_mass());
    else:
        apply_impulse(Vector3(), direction * air_accel * get_mass());
    state.integrate_forces();

func _ready():
    set_process_input(true);

func _fixed_process(delta):
    if not Input.is_action_pressed("move_forward"):
        get_node("body/camera/Spatial/AnimationPlayer").stop()
        should_play_anim = true

    if Input.is_key_pressed(KEY_W) and should_play_anim:
        get_node("body/camera/Spatial/AnimationPlayer").play("walking")
        should_play_anim = false

func _enter_tree():
    Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED);

func _exit_tree():
    Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE);

any help would be appreciated.

in Engine by (81 points)

2 Answers

0 votes
Best answer

Try adding

    set_fixed_process(true);

in your func _ready():

and see if that helps

by (484 points)
selected by

thank you so much.

0 votes

Yes, try

func_ready():
    set_fixed_process(true);
    set_process_input(true);

as you said the The_Duskitty

I've arrived late :(

by (84 points)

Heh ;P I sit around on here like almost all day while working on stuff, 's why i have so many questions on here XD

Help with what i do know, just wait for somebody else to answer something i dont know so i can learn to know it XD

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.