fabriceci / godot-rapier2d

GDExtension for Rapier2D
MIT License
15 stars 3 forks source link

When the player moves toward another CharacterBody2D weird movement happens #41

Open TheDWPCer opened 11 months ago

TheDWPCer commented 11 months ago

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
Ughuuu commented 11 months ago

Oh my god that is hilarious. Thanks for reporting it also, will investigate. Can you also upload a zipped project?

TheDWPCer commented 11 months ago

https://drive.google.com/file/d/199qNLjC51CV6f-e35TkjjM3gg3gCj-Bl/view?usp=drive_link let me know if that works (I might of changed the physics engine before I sent it, make sure it's on rapier2d). Also let me know if the link doesn't work.

Ughuuu commented 11 months ago

Added more info to the other repo(where I will continue this)