0 votes

Hi Everyone!
I'm new here, so... I got torubles lol
I'm a studen at university and i gotta do a game for my final (best thing ever S2), everything was going quite smoothly but now i'm in a pinch
I've tried and look, and google, and going to the bottom of internet to find a way to make the magic beam leaves a staff, from a boss in constant and random movement, and collides to the player, whatever his position is.

I really wish I could show my code raws, but they're just crazy mess.
u can help me with tutorials links, youtube links or other crazy but more functional ideas!!
This projet is looking awesome, really but i got a tight deadline (06/09) (my cpu died and i'm currently at my bf notebook, w/o a lot of my work)

Thank you !
(people who can write in spanish I aprecciate, i know english but spanish is a lot easier - i'm brazilian)

in Engine by (12 points)

1 Answer

0 votes

there is a function called look_at in transform class, you can use that i believe.

first calculate the distance between tip of staff and the player
then create your "beam" rectangle
then place that rectangle to tip of staff and set transform of that rectangle with a transform that looked player.

you may have to play with x and y values of location of that beam but i think this is da way.

by (26 points)

God, I really thought this would work but maybe it's cause my code is a basic mess, i'm trying simply everything i see on internet... in my head the code works, but reality not so much

In the boss scene, I'm trying to make the bullet locate the player, I tried figuring out what u sugested ("calculate the distance"), but if my player is constantly moving, and so is the Boss, how do I calculate this? LoL

This is my mess, I don't know if the problem is I'm using a Static Body or not, or everthing else
(it keeps appearing the null instance error for global_position)

`extends StaticBody2D

var speed = 100
onready var player = preload("res://Player.tscn").instance()

func ready():
set
process(true)

func _process(delta):
shoot()

func shoot():
getparent().getnode(".").addchild(player)
var shot = preload("res://Beam.tscn").instance()
var direction = (look
at(player.globalposition) - $muzle.globalposition).normalized()
shot.globalposition = $muzle.globalposition
shot.dir = Vector2(cos(rotation), sin(rotation)).normalized()
getparent().getnode(".").add_child(shot)`

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.