Godot Version
V4.6
Question
Hello, I have a projectile(character body) that moves and collide then bounces off a character body.
The issue is that the projectiles don’t bounce off of moving bodies and instead they pile up. How would I go about implementing the physics so the projectiles bounce off all bodies.
Projectile physics process:
func _physics_process(delta: float) -> void:
collision = move_and_collide(velocity*delta)
if collision:
collider=collision.get_collider()
velocity = velocity.bounce(collision.get_normal())
##Friction
if velocity.length() > 0:
var drop = friction * delta
var new_speed = max(velocity.length() - drop, 0)
velocity = velocity.normalized() * new_speed
Character processes:
func _process(delta: float) -> void:
##get mouse position and rotates the shield towards mouse position
var aim = get_global_mouse_position() - $Node2D.global_position
if aim.length() > dead_zone_shield:
$Node2D.rotation = lerp_angle($Node2D.rotation,aim.angle(), 0.2)
$Node2D/Shield.ball_dir=($Node2D.get_global_mouse_position()-$Node2D.global_position).normalized()
func _physics_process(delta: float) -> void:
var target_pos = get_global_mouse_position()
var to_mouse = target_pos - global_position
var input = Vector2.ZERO
##moves the character towards mouse
if to_mouse.length() > dead_zone_moving: # dead zone
input = to_mouse.normalized()
var lerp_weight = delta * (acceleration if input != Vector2.ZERO else friction)
velocity = lerp(velocity, input * (max_speed+to_mouse.length()), lerp_weight)
move_and_slide()

