Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | arthurZ |
Hi, I’m following the KidsCanCode course ‘Godot 101 - Part 9: Arcade Physics (https://www.youtube.com/watch?v=oy9L0b5X0BY)’ and I’m trying to convert from his code in godot 2.1.2 to godot 3.0.
So, what I want to know is:
-
Are there a
is_colliding()
and aget_collision_normal()
functions to godot 3?? If yes, what are the names of them? -
How could I use the contact normal between the platform and walls with the
move_and_slide()
? As the second argument? -
Is the
is_on_floor()
the right way to check the contact or for this code is better another one? Will this work with a slope floor?
Note: I’m new to gamedev and some concepts about it.
Note2: Until that point my code is working.
a) The KidsCanCode code:
extends KinematicBody2D
const ACCEL = 1500
const MAX_SPEED = 500
const FRICTION = -500
const GRAVITY = 2000
var acc = Vector2()
var vel = Vector2()
func _ready():
set_fixed_process(true)
func _fixed_process(delta):
acc.y = GRAVITY
acc.x = Input.is_action_pressed("ui_right") - Input.is_action_pressed("ui_left")
acc.x *= ACCEL
if acc.x == 0:
acc.x = vel.x * FRICTION * delta
vel += acc * delta
vel.x = clamp(vel.x, -MAX_SPEED, MAX_SPEED)
var motion = move(vel * delta)
if is_colliding():
var n = get_collision_normal()
motion = n.slide(motion)
vel = n.slide(vel)
move(motion)
b) My code:
extends KinematicBody2D
const ACCEL = 1500
const MAX_SPEED = 500
const FRICTION = -500
const GRAVITY = 2000
var acc = Vector2()
var vel = Vector2()
func _ready():
pass
func _physics_process(delta):
acc.y = GRAVITY
acc.x = int(Input.is_action_pressed("ui_right")) - int(Input.is_action_pressed("ui_left"))
acc.x *= ACCEL
if acc.x == 0:
acc.x = vel.x * FRICTION * delta
vel += acc *delta
vel.x = clamp(vel.x, -MAX_SPEED, MAX_SPEED)
move_and_slide(vel)
if is_on_floor():
pass