godot-rapier2d icon indicating copy to clipboard operation
godot-rapier2d copied to clipboard

When the player moves toward another CharacterBody2D weird movement happens

Open TheDWPCer opened this issue 1 year ago • 3 comments

Godot 4.2beta1 Windows 10 I'm not sure what exactly is need to test this but here is a video of the problem (let me know if you need more info) (There is also some collision weirdness that I'm not sure how to fix)

https://github.com/fabriceci/godot-rapier2d/assets/15698234/d84ba8d2-e2a4-4152-9f49-ed5fedb0236d

Here is the code for the player character

extends CharacterBody2D


const SPEED = 150.0
const SPEED_MULTI = 2
const JUMP_VELOCITY = 400.0
var multipler: int = 1
var mouse_position: Vector2i 
@export var texture: Texture2D

# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity")

func _physics_process(delta: float) -> void:
	# Add the gravity.
	if not is_on_floor():
		velocity.y += gravity * delta

	# Handle Jump.
	if Input.is_action_just_pressed("jump") and is_on_floor():
		velocity.y = -JUMP_VELOCITY

	# Get the input direction and handle the movement/deceleration.
	# As good practice, you should replace UI actions with custom gameplay actions.
	var direction := Input.get_axis("ui_left", "ui_right")
	if Input.is_action_pressed("sprint"):
		multipler = 2
	else:
		multipler = 1
	
	if direction:
		velocity.x = direction * SPEED * multipler
	else:
		velocity.x = move_toward(velocity.x, 0, SPEED)
		
	
	move_and_slide()

And here is the script for the moving block

extends CharacterBody2D
@export var speed :float = 60

func _ready() -> void:
	pass


func _physics_process(delta: float) -> void:
	velocity.x = delta*speed
	move_and_slide()
	pass

TheDWPCer avatar Oct 22 '23 06:10 TheDWPCer