Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | wombatTurkey | |
Old Version | Published before Godot 3 was released. |
Alrighty, so this is what I get for failing Math so bad at school! Forgive me in advance…
Anyways.
My character basically clicks anywhere on the map, and he gets to shoot a fireball:
Here is the code for that:
for number_of_projectiles in range(3):
var scene = load("res://Skills/Fireball.tscn") # will load when parsing the script
var temp_skill = scene.instance()
var angle = gg.players[1].get_global_mouse_pos().angle_to_point(gg.players[1].get_pos())
var mpos = gg.players[1].get_global_mouse_pos()
var ang = gg.players[1].get_angle_to(mpos)
temp_skill.set_pos(gg.players[1].get_pos())
temp_skill.add_collision_exception_with(gg.players[1]) # Cannot collide with self
for x in gg.Live_Skills:
temp_skill.add_collision_exception_with(gg.Live_Skills[x]) # Cannot collide with these same bodies
var X = 250 * sin(angle);
var Y = 250 * cos(angle);
temp_skill.newMove = Vector2(X, Y)
temp_skill.set_rotd(rad2deg(angle) - 90)
get_tree().get_root().get_node("world/Levels/Map").add_child(temp_skill)
gg.Live_Skills[temp_skill.get_name()] = temp_skill
And for my Fireball.gd:
func _fixed_process(delta):
if (hit):
return
move(newMove*delta)
if (is_colliding()):
get_node("anim").play("explode")
hit = true
So, for this example there is 3 projectiles (number_of_projectiles
)
I need to find the Math algorithm here to separate them out evenly, for example. If I am shooting 3
projectiles, it shows them overlapping:
I need to play with number_of_projectiles
and use them with the sin
and cos
methods so I can evenly separate them into a “projectile” wave. This is where I’m stuck because I just am not sure how to do it.
I’ve tried sin(angle) * number_of_projectiles
but, with unexpected results (the fireballs all go at different speeds and in 1 straight line).