Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kinematic body slides off slopes that is supposed to snap to when landing #30777

Closed
Vlad-Zumer opened this issue Jul 23, 2019 · 1 comment
Closed

Comments

@Vlad-Zumer
Copy link
Contributor

Godot version:
3.1.1

OS/device including version:
Windows 10 x64

Issue description:
Kinematic body slides off slopes that is supposed to snap to when landing.

kinematic_body_move_slide_snap

Steps to reproduce:
use this script on a kinematic body 2d with any collider.
jump on a slope >=45 deg

extends KinematicBody2D

# Declare member variables here. Examples:
# var a = 2
# var b = "text"

export var gravity: = Vector2(0,4)
export var moving_vel: = Vector2(8,0)
export var jumping_vel: = -Vector2(0,50)

var _totalVel: Vector2
var _vel_remainder: Vector2 = Vector2.ZERO

# Called when the node enters the scene tree for the first time.
func _ready():
#	jumping_vel-=gravity
	print(jumping_vel)
	pass # Replace with function body.

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
	var _snapVec = Vector2(0,64)	
	_totalVel.x = 0
	if !is_on_floor():
		_totalVel += gravity
	else:
		_totalVel.y = 0
		_totalVel += jumping_vel * int(Input.is_action_just_pressed("ui_up"))
		_snapVec -= int(Input.is_action_just_pressed("ui_up"))*_snapVec
	_totalVel += moving_vel * (-int(Input.is_action_pressed("ui_left")) + int(Input.is_action_pressed("ui_right")))
	if (_totalVel.y > 0):
		print(_totalVel)
	if(!is_on_floor()):
		print(is_on_floor())
	move_and_slide_with_snap(_totalVel*64,_snapVec,Vector2(0,-1),false,4,45.0)

Minimal reproduction project:
KinematicBody2D_reprod.zip

This issue #26274 seems close to mine but the effects are different.
Please move if needed

@KoBeWi
Copy link
Member

KoBeWi commented Sep 25, 2020

Soo the floor angle is in radians not degrees. Also if you want to prevent sliding, pass true to stop on slope.

This tweak fixes the issue:
move_and_slide_with_snap(_totalVel*64,_snapVec,Vector2(0,-1),true,4,0.8)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants