Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | edimemune | |
Old Version | Published before Godot 3 was released. |
I have been learning Godot Engine for a month and I tryed to make a game from start to finish to gain experience. I made a ball with physics that moves with a tilemap. But I don’t understand the difference between this two functions: move_and_slide()
and move()
. When I used move to move the ball, it was moving very slow when touching the ground, now when I am using move_and_slide()
function it works properly.
Here is the code:
extends KinematicBody2D
export var viteza = 30
var animNod
var jumped = false
var falling = false
var y
func _ready():
animNod = get_node("AnimatedSprite")
set_fixed_process(true)
func _fixed_process(delta):
#MISCARE
delta *= 10
var misc = Vector2(0,1)
if(jumped):
if(get_pos()[1] > y and not falling):
print("Da")
misc[1] = -1
elif(get_pos()[1] <= y):
falling = true
if(Input.is_key_pressed(KEY_D) or Input.is_key_pressed(KEY_RIGHT)):
misc[0] = 1
if(Input.is_key_pressed(KEY_A) or Input.is_key_pressed(KEY_LEFT)):
misc[0] = -1
misc = misc * (delta * viteza)
#here was move function
self.move_and_slide(misc*100)
#ANIMATIE
var newAnim = "idle"
if(Input.is_key_pressed(KEY_D) or Input.is_key_pressed(KEY_RIGHT) or Input.is_key_pressed(KEY_A) or Input.is_key_pressed(KEY_LEFT)):
newAnim = "mers"
#Jump --->
if((Input.is_key_pressed(KEY_SPACE) or Input.is_key_pressed(KEY_W)) and not jumped):
jumped = true
var jH = 50
y = get_pos()[1] - jH
print(jumped)
#<--- Jump
animNod.play(newAnim)
var corp = get_collider()
if corp != null:
if corp.is_in_group("sol") and falling:
jumped = false
falling = false
What the difference between them? And what does each of them?
Hello from the future!
Im using 3.0.2 stable and this glitch is still in place. Almost exactly the same. Im doing a:
var direction
direction.x = int(Input.is_action_pressed()) - int(Input.is_action_pressed())
direction.y = int(Input.is_action_pressed()) - int(Input.is_action_pressed())
move_and_slide(direction.normalized() * speed)
When checking in the console, the sprite gets stuck when the direction is Vector2(0,1)
batomow | 2018-06-14 04:40