Community

D
Spuncer

When the enemy has gravitation he cannot climb the ramps

I am not succeeding in solving a bug, where when the enemy has gravitation interacting with him, he cannot climb the ramps

extends "res://asc/actors/Actor.gd"

var snap: = Vector2.DOWN * 65.0

_velocity.x = -speed.x

func _on_StompDetector_body_entered(body: Node) -> void:
var physic_body = body as PhysicsBody2D
if physic_body.global_position.y > \$StompDetector.global_position.y:
return
\$CollisionShape2D.disabled = true
queue_free()

func _physics_process(delta: float) -> void:
if is_on_wall():
_velocity.x *= -1

_velocity.y += gravity
_velocity.y = move_and_slide_with_snap(_velocity,snap,FLOOR_NORMAL).y

Now when he doesn't have gravitate interacting with him, he climbs the ramps perfectly. Why does it happen?

extends "res://asc/actors/Actor.gd"

var snap: = Vector2.DOWN * 65.0

_velocity.x = -speed.x

func _on_StompDetector_body_entered(body: Node) -> void:
var physic_body = body as PhysicsBody2D
if physic_body.global_position.y > \$StompDetector.global_position.y:
return
\$CollisionShape2D.disabled = true
queue_free()

func _physics_process(delta: float) -> void:
if is_on_wall():
_velocity.x *= -1

_velocity.y = move_and_slide_with_snap(_velocity,snap,FLOOR_NORMAL).y
• D
Spuncer replied

Well I manage to solve this problem as follows:

func _physics_process(delta: float) -> void:
var snap: = Vector2.DOWN * 65.0
if is_on_wall():
_velocity.x *= -1

_velocity.y += gravity * delta
_velocity.y = move_and_slide_with_snap(_velocity,snap,FLOOR_NORMAL, true, 4, PI/3).y