Godot Version
4.2.2
Question
extends CharacterBody2D
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
var gravity = ProjectSettings.get_setting(“physics/2d/default_gravity”)
func _physics_process(delta):
if not is_on_floor():
velocity.y += gravity * delta
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
var direction = Input.get_axis("ui_left", "ui_right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
var collision = move_and_collide(velocity)
var collider
if collision:
collider = collision.get_collider_velocity()
velocity = 10*collider
i need move_and_collide because i have another character 2d node that needs to be able to shove the main [the code above] character2d node
but whenever i add move_and_collide into my code it makes the play move too fast but also really slow on slopes
another way to detect player collision or to stop move_and_collide from doing that would be great
(i mean yeah i could use area2d and make it slightly larger then the player but then i’d need to code in what happens when the player enters from what angle)