0 votes

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:

1) Are there a is_colliding() and a get_collision_normal() functions to godot 3?? If yes, what are the names of them?

2) How could I use the contact normal between the platform and walls with the move_and_slide()? As the second argument?

3) 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
in Engine by (173 points)
edited by

1 Answer

+1 vote

There is no is_colliding() anymore or a get_collision_normal(), instead you have the move_and_slide() function which does that for you, just remember to set the outgoing velocity from the move_and_slide so if you hit a wall it will stop the character... but you do get to have stuff like is_on_floor() and is_on_wall() which is nice

by (1,197 points)
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.