How to make a player move along with the platform?

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

Hi people,

I wanted to know an easier way and that I can understand, How to make the player move around with the platform.

I know Godot has a 2d platformer demo, But I cannot understand that part.
I wanted something simple and easy to understand, Like this tutorial:

http://docs.godotengine.org/en/stable/tutorials/2d/kinematic_character_2d.html?highlight=kinematic

So can anyone help me?

:bust_in_silhouette: Reply From: avencherus

Generally you add your platform velocity to the player’s velocity, when they’re standing on it.

In the platformer code it’s this: https://github.com/godotengine/godot-demo-projects/blob/master/2d/kinematic_char/player.gd#L104

Is not working, The player does not follow the platform :confused:
Help me please!

ismaelgame7 | 2017-04-08 18:18

:bust_in_silhouette: Reply From: ismaelgame7

extends KinematicBody2D

export var walk = true

const GRAV = 450
const SPEED = 230
const JUMP = -430

var vel = Vector2()
var jumpOk = true
var playerSelf = self

func _fixed_process(delta):
vel.y+=delta*GRAV

var floor_velocity = Vector2()

if walk == true:
	if (Input.is_action_pressed("Btn_left")):
		vel.x = -SPEED
		playerSelf.set_scale(Vector2(-1,1))
		playerSelf.get_node("AnimatedSprite").set_animation("Ruan_Run")
		
	elif (Input.is_action_pressed("Btn_right")):
		vel.x = SPEED
		playerSelf.set_scale(Vector2(1,1))
		playerSelf.get_node("AnimatedSprite").set_animation("Ruan_Run")
		
	else:
		vel.x = 0
		playerSelf.get_node("AnimatedSprite").set_animation("Ruan_Default")
		
elif walk == false:
	vel.x = 0
	playerSelf.get_node("AnimatedSprite").set_animation("Ruan_Default")


var cair = vel*delta
move(cair)

floor_velocity = get_collider_velocity()

if (is_colliding()):
	var colidindo = get_collider()		
	var n = get_collision_normal()
	cair = n.slide(cair)
	vel = n.slide(vel)
	move(cair)
	


var foot = get_node("Rc2D")
var foot2 = get_node("Rc2D1")
foot.add_exception(self)
foot2.add_exception(self)

if foot.is_colliding() || foot2.is_colliding():
	if (Input.is_action_pressed("Btn_up") and jumpOk == true and walk == true):
		vel.y = JUMP
		jumpOk = false
	if! (Input.is_action_pressed("Btn_up")):
		jumpOk = true
	pass
pass

func _ready():
set_fixed_process(true)
pass

Here my code me help to make the player moves with the platform, please!

:bust_in_silhouette: Reply From: eons

You are not adding the floor_velocity to the movement vector, also, just do that only if colliding (and get collider velocity only if colliding).


Moving platforms, in general, are between the 4th and 7th circles of hell so, be patient because you may face a some issues depending on your game mechanics.

I suggest you to do some little tests first, create a simple body affected by gravity vector only, then create the platform, move the platform and try to make the body follow the platform displacement, then apply user input and see how works until you find the motion effect you want.

:bust_in_silhouette: Reply From: ismaelgame7

Hello,

Sorry for bothering you with the same subject.
I can not catch the speed of my platform and move to my player.
I know there is a function called get_collision_velocity, But I have no idea how to use.

There is no tutorial on the internet speaking or teaching about it!
The only thing that has it’s a demo and it’s complex.
It’s frustrating to see things not working.