Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Pavel Kotlyar | |
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 speed
is - 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