Can't change KinematicBody2D speed

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Pavel Kotlyar
:warning: Old Version Published before Godot 3 was released.

Hi,

I am having a strange issue with the setting of speed for KinematicBody2D, No matter what the value for speedis - the node speed does not change, it is kind of like a constant…

Here is the code:

extends KinematicBody2D

export var speed = 250

onready var screen_size = get_viewport_rect().size
var motion = Vector2()

func _ready():
	set_initial_position()
	set_fixed_process(true)

func set_initial_position():
	randomize()
	var inital_y_position = int(rand_range(160, screen_size.y - 160))
	set_pos(Vector2(0, inital_y_position))

func _fixed_process(delta):
	motion += Vector2(1, 0)
	motion = motion.normalized() * speed * delta
	move(motion)
	
	if(get_pos().x > screen_size.x + get_node("Sprite").get_texture().get_size().x):
		set_initial_position()

I’ve noticed that I have the same problem with another KinematicBody2D on the Scene which is a Player both of them are moving with exactly the same speed here the Player code https://github.com/paxer/marine_treasure_hunter/blob/master/scenes/main/player.gd

I also tried instead of using ofmove -

func _fixed_process(delta):
	var fish_position = get_pos()
	fish_position.x += speed * delta
	set_pos(fish_position)

still the same, the speed doesn’t change, I instantiate both in a main scene https://github.com/paxer/marine_treasure_hunter/blob/master/scenes/main/main.gd but to me, there is nothing special there what could cause the problem

:bust_in_silhouette: Reply From: CowThing

export var speed means the variable is exported, which means it can be edited in the scene like other properties of a node. When the scene loads it will set speed to the value set in the scene. If you want to change the value click on the node that has this script and edit the value there. Or remove the export keyword if you only want to edit the value within the script.