Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Lado |
Hello, world! I am new in Godot and I am having trouble getting my fireball to react properly, I want them to reflect off the normals of my wedges like a mirror when I shoot. I decided to use RigidBody2D for this reason. But I cannot get the direction to change at each collision.
Please help me solve this issue, and understand the solution, thanks.
This is my script
extends RigidBody2D
var velocity = Vector2()
const speed = 60
var direction = 1
#var direction = Vector2()
func set_fireball_direction(dir):
direction = dir
if dir == -1:
$AnimatedSprite.flip_h = true
func _physics_process(delta):
velocity.x = speed * delta * direction
set_linear_velocity(velocity)
#set_bounce(1)
$AnimatedSprite.play("fire")
func _on_Area2D_body_entered(body):
if "TileMap" in body.name:
set_bounce(1)
So this is not an answer, but I wondering about little things for trying to help you.
I’m not sure what your trying to achieve, but there are maybe many solutions.
I’m not an expert about rigidbody2D but I may have done some test with it.
With a Mode set to Rigid, it should collide and bounce without any code processing, I think you should use something different from area2D like a StaticBody2D, and if you dont want others part to collide or interact with it, collision layer and mask must be the solution (read the infobulle help when hovering your cursor on it).
Maybe I’m wrong but it would be more simplier to have a look with the real project if you can ?
I also have somecode suggestion for helping (don’t worry, I’ve also done those weird things at first) :
# if "TileMap" in body.name:
if body is TileMap :
set_bounce(1)
# this will set the bounciness and should be set with a physics_material_override in the editor
# it only tell how much the rigidbody2D is bouncy, and don't do anything than that
Luck_437 | 2020-04-12 15:41
I want something like this but I don’t have an idea how to implement it
So the idea is when press button for shooting a fireball. It hits to the mirror and then struggles from that mirror
Lado | 2020-04-12 18:28