Godot Version 4.2.1
Question
Ball: RigidBody2d
Rectangle: CharacterBody2d
Both have collisionShape2d
I have an _on_body_entered func inside the ball script that prints “working” when collision is detected. Working is only being printed when contact is made with the corner of the rectangle and not the faces.
End goal would be to apply forces to the ball based on the contact made with the rectangle. Issue is current collision is not detected on the faces in order to then add that code.
Code is below for both entities. I would post video but as a new user I am unable to.
Rectangle code
extends CharacterBody2D
#Button Variables
@export var SPEED: int = 40000
#Touch Variables
var dragging = false
var offset = Vector2(0,0)
func _physics_process(delta: float) -> void:
#Button Movement
var direction = Input.get_axis("Left", "Right")
if direction:
velocity.x = direction * SPEED * delta
else:
velocity.x = 0
#Touch Movement
if dragging:
var newPos = get_global_mouse_position() - offset
position = Vector2(newPos.x,280)
move_and_slide()
func _on_button_button_down() -> void:
dragging = true
offset = get_global_mouse_position() - global_position
func _on_button_button_up() -> void:
dragging = false
Ball Code
extends RigidBody2D
var velocity = Vector2(350, 350)
func _physics_process(delta: float) -> void:
var collisionInfo = move_and_collide(velocity * delta)
if collisionInfo:
velocity = velocity.bounce(collisionInfo.get_normal())
func _on_body_entered(body: Node) -> void:
if body.is_in_group("Player"):
print("working")