Тёмный

Shooting a Bullet - Godot Tutorial 

Arith metic
Подписаться 1,4 тыс.
Просмотров 75 тыс.
50% 1

I realized that I hadn't covered instancing objects. A topic that my next tutorial would need you to know about before starting. Because of this, I thought I would make a video covering it in one of the best ways possible. Shooting a bullet. Hope you enjoy it and leave a comment letting me know what you thought of the video.
#DiskArena #Tutorial #Shoot #IndieGameDev #Godot #2D #TopDown #PixelArt #Bullet #Multiplayer #Powerup

Игры

Опубликовано:

 

6 мар 2021

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 230   
@CfopCubing
@CfopCubing Месяц назад
"instance" is now "instantiate" "Position2D" is now "Marker2D"
@manishkanyal10a18
@manishkanyal10a18 28 дней назад
thanks bro
@alondovrat
@alondovrat 26 дней назад
thank you so much i got stuck on it for like 30 minutes so i checked the comments thanks man
@tenguxxc4905
@tenguxxc4905 Год назад
if anyone is wondering why is not working if you are using godot 4 the reason is that u should be using "instantiate" instead of "instance"
@arithmetic1938
@arithmetic1938 Год назад
That's good to know thanks 👍
@duxverseinteractive
@duxverseinteractive Год назад
But what should i do if i have an this kind of error: Cannot get return value of call to "action_press()" because it returns "void".
@captainpanic3616
@captainpanic3616 Год назад
@@duxverseinteractive I used "is_action_pressed()" instead
@happygofishing
@happygofishing 9 месяцев назад
thanks
@JOZUWE
@JOZUWE 6 месяцев назад
THANK YOU!!!
@nighthawk__0617
@nighthawk__0617 3 года назад
Like it, straightforward just the thing you need when having just "One" Problem.
@arithmetic1938
@arithmetic1938 3 года назад
I'm glad you liked it, hope it helps.
@Ozzymandias0
@Ozzymandias0 2 года назад
Thanks mate, I was in a gamejam and this tutorial really helped me
@arithmetic1938
@arithmetic1938 2 года назад
I'm glad I could help. Hope you did well in the game jam
@haotehmao
@haotehmao 2 года назад
Life saver! The only tutorial that worked for me!
@arithmetic1938
@arithmetic1938 2 года назад
Glad I was able to help 😊
@maulanazn_exceedmemory
@maulanazn_exceedmemory Год назад
thank you so much, really helpful.Appreciate it dude😀
@arithmetic1938
@arithmetic1938 Год назад
Glad I could help
@henryd3bby
@henryd3bby 2 года назад
thank you very much! I'm currently making a game, and i have problem with stomping enemy physics, so this video really helped me out! Thanks bud, i'll credit you when the development of my game finishes, btw, have an amazing day!
@arithmetic1938
@arithmetic1938 2 года назад
Glad I could help. I wish you the best of luck on your game
@henryd3bby
@henryd3bby 2 года назад
@@arithmetic1938 thx
@negativefg7922
@negativefg7922 2 года назад
Thank you, kind man, we are developing game with my friend and total rookies when it comes to code, and without this tutorial we would just stuck in the creating of bullet.
@arithmetic1938
@arithmetic1938 2 года назад
I'm glad I was able to help, and I wish you the best of luck on your game 😊
@lemone12
@lemone12 2 года назад
This is the first time i have seen someone type out the object path, you are on a next level
@arithmetic1938
@arithmetic1938 2 года назад
I think I don't realize I could drag it in at the time. Although I'm pretty good at typing out the path so I might as well show it off XD
@antonyxd5270
@antonyxd5270 2 года назад
tysm, this is the only tutorial that worked for me
@arithmetic1938
@arithmetic1938 2 года назад
I'm glad it was able to help you
@santiromero7057
@santiromero7057 2 года назад
Thanks mate, I've been looking at all these confusing tutorials, but yours is the first that really seems like a step by step guide. Really appreciate it
@arithmetic1938
@arithmetic1938 2 года назад
I'm glad I was able to help ☺️
@BrightLikeSnow
@BrightLikeSnow 6 месяцев назад
Thank you so much man. Me and my friend are new to godot so I naturally challenged him to make a little shooting characters. We got so close but couldnt figure it out.😅amazing video!
@arithmetic1938
@arithmetic1938 6 месяцев назад
Glad I could help. I wish you the best of luck with creating projects as time goes on
@maxave7448
@maxave7448 2 месяца назад
This was really helpful, thanks!
@shinypikachu4466
@shinypikachu4466 8 месяцев назад
Thx this was very straightforward
@arithmetic1938
@arithmetic1938 7 месяцев назад
I'm glad I could help 😁
@darchankaen1307
@darchankaen1307 Год назад
Awesome tutorial! The first, after which my game work.
@arithmetic1938
@arithmetic1938 Год назад
Great to hear!
@dheynmichaelorlanda5370
@dheynmichaelorlanda5370 2 года назад
Nice, I'll try it now
@rajithaharshanathsenanayak5908
@rajithaharshanathsenanayak5908 10 месяцев назад
Thank you so muck.. This video is like a diamond which I found...❤
@arithmetic1938
@arithmetic1938 7 месяцев назад
Thanks I appreciate that
@be_safe_and_brave_and_smart
@be_safe_and_brave_and_smart 5 месяцев назад
bro this is amazing
@soundrogue4472
@soundrogue4472 11 месяцев назад
3:38 Thank you! That's the one issue I had in my code!
@arithmetic1938
@arithmetic1938 7 месяцев назад
I'm really glad I included that in my video then. 😁
@jake4andrws26
@jake4andrws26 10 месяцев назад
i dont expect a response but it's worth a shot. The bullet just doesn't move at all. func shoot(): if Bullet: print("bullet made") var bullet_instance = Bullet.instantiate() bullet_instance.position = get_global_position() bullet_instance.rotation_degrees = rotation_degrees + 90 bullet_instance.apply_impulse(Vector2(), Vector2(bullet_speed, 0).rotated(rotation)) get_tree().get_root().add_child(bullet_instance) it just spawns in on the player sprite
@RynthCats
@RynthCats 9 месяцев назад
i didnt use an apply impulse and im new to godot. but maybe you could use add_constant_force. or just use a kinematicbody2d and use move_and_slide().
@arithmetic1938
@arithmetic1938 7 месяцев назад
Make sure that you have the bullet script built correctly. Velocity set to direction times speed and move and slide called. Sadly this is an older video and it's not the most up to date with Godot 4, but I wish you the best of luck
@apaaja2185
@apaaja2185 2 года назад
thank you very much bro
@arithmetic1938
@arithmetic1938 2 года назад
Glad I could help
@peedtron
@peedtron 2 года назад
Amazing Tutorial, thank you so much , i always had the bug that the bullet follows the play position
@arithmetic1938
@arithmetic1938 2 года назад
Glad I could help
@havenandaura
@havenandaura Год назад
This tutorial is great for Godot 4.0 with a few conversions but something I'm not able to get working is get_global_mouse_position(), it keeps saying it can't be used in base "self" and I'm not sure how this is happening because I'm operating in the same workspace you are, and documentations for this are mind-breaking
@alejandrolemus7076
@alejandrolemus7076 8 месяцев назад
Your root node needs to be Node2D; You probably just have it at Node. Make sure to also change the extends node portion to extends node 2D if you already have existing code
@cyberslava8982
@cyberslava8982 Год назад
TYSM!!
@arithmetic1938
@arithmetic1938 Год назад
You're welcome 🤗
@mcscwiggles1201
@mcscwiggles1201 Месяц назад
How do I get this to work? In my game, i dont want to have the bullet follow my mouse. Rather when the player flips left or right, the bullet with then shoot left or right. I was able to follow your vid and get the bullet to shoot to the right fine. Just need to be able to shoot to the left when the player faces left. Any ideas would be great ❤
@Chubbuluss
@Chubbuluss Год назад
How would I get the bullet to rotate to face the correct direction? They always come out looking directly to the right. And how do I get the bullet to despawn when it hits something? This tutorial feels unfinished..
@arithmetic1938
@arithmetic1938 Год назад
There are quite of bit of different ways that bullets work in different video games. I can't cover all of them. This video is simply for creating bullets and getting them to move in the direction you want. For despawning bullets you'll want to add collision detection and have it call queue_free() on thebullets. For rotation you can use the look_at() function. If you have trouble figuring it out feel free to hop on my discord (link in the description) and ask a question in the help channel
@volcano3864
@volcano3864 2 года назад
it is easier than I thought
@nikkinkhv
@nikkinkhv 5 месяцев назад
Oh thanks
@gekah77
@gekah77 2 года назад
having a problem, it says: “Invalid set index ‘velocity’ (on base: Node2D’) with the value of type ‘Vector2’”
@arithmetic1938
@arithmetic1938 2 года назад
From that error I would guess that your velocity is a different type than Vector2
@skvader4187
@skvader4187 Год назад
​@@arithmetic1938 i have the same error, yet i dont see any difference between your and my code. "var velocity = Vector2(0,0)"
@micahrobbins8353
@micahrobbins8353 Год назад
Super cool, does anyone have any ideas on how to orient the bullet sprite towards the mouse? I'm guessing it has to happen when it's instanced by the player
@arithmetic1938
@arithmetic1938 Год назад
You should be able to do something like this in the bullets process function `look_at(position + velocity)` That with rotate the bullet based on the velocity
@micahrobbins8353
@micahrobbins8353 Год назад
Oh my g*sh thank you so much :)
@RainierFajardoProduction
@RainierFajardoProduction Месяц назад
Godot 4.2 sucks man. I can't do this. I've been trying for weeks now :( The hunting aspect of my game is slowly gone :(
@bhBlacky82
@bhBlacky82 Год назад
im relatively new.. so i wonder.. can you just create a rigidbody as bullet and apply an opposite direction force? so that's an actual physical bullet?
@arithmetic1938
@arithmetic1938 Год назад
Ya you definitely could. If you wanted to. I usually use kinematic body as it's easier to control
@bog_champ2172
@bog_champ2172 2 года назад
I am using this for my tank game and I have a problem, the Position2D is following the mouse and not rotating I tried clamping its position but that didn't work.
@arithmetic1938
@arithmetic1938 2 года назад
From that description I assume that you're having the position2D look at the mouse when you should be having its parent look at the mouse. The object will rotate at it's center point which having 2 different nodes will allow you to change more easily. If you need to you can add in an extra node who has the soul purpose of being a rotation point for the position2D. If you need more help don't be afraid to ask. You can also post screen shots into the help channel on discord (link in the description) if needed
@smutnazaba2365
@smutnazaba2365 21 день назад
Hi Thats Tutorial Is Good But I Have Problem Cuz When I Wanna Test My Game and Click Something The Game Just Stops and I Need Quit, Whats Wrong?
@oct8530
@oct8530 2 года назад
mine just says: Parser Error: The identifier "velocity" isn't declared in the current scope. please help
@arithmetic1938
@arithmetic1938 2 года назад
For this error that means that you don't have velocity in the script but your trying to call it. I assume you're missing a `var velocity = Vector2(0, 0)` at the top of the script
@kpts1059
@kpts1059 3 года назад
Hello! What can be the reason of this warning? Invalid type in function 'get_child' in base 'YSort'. Cannot convert argument 1 from Object to int.
@kpts1059
@kpts1059 3 года назад
Oh, I could solve it! Thanks for the video!
@matheusmelo8685
@matheusmelo8685 3 года назад
Hey man, how did you solve it? Just to know, cause i have the same problem
@kpts1059
@kpts1059 3 года назад
@@matheusmelo8685 omg. I'm sorry but I forgot what I had done about the problem
@kpts1059
@kpts1059 3 года назад
@@matheusmelo8685 ig it was related to the setting of the another node as a child in main scene, maybe this code can help you: func shoot(): #function set up for shooting var bullet = BulletPath.instance() get_parent().add_child(bullet) bullet.rotation = $Sprite/Gun.global_rotation bullet.position = $Sprite/Gun.global_position bullet.velocity = get_global_mouse_position() - bullet.position
@kpts1059
@kpts1059 3 года назад
@@matheusmelo8685 and the BulletPath is this: const BulletPath = preload("res://Bullet.tscn")
@nhuleneusse7645
@nhuleneusse7645 26 дней назад
For anyone getting the (Member "velocity" redifened) ERROR: now vector2() is part of velocity in GODOT 4 so you simply have to deleted the 3rd line in the video
@TimberLine534
@TimberLine534 15 часов назад
Thanks man
@bogslonca
@bogslonca 23 дня назад
KinematicBody2D is now CharacterBody2D
@brayantube7311
@brayantube7311 3 года назад
I love you
@arithmetic1938
@arithmetic1938 3 года назад
And I love you random internet person, here have a ❤️ 😊
@user-rb4mk6hk9z
@user-rb4mk6hk9z 7 месяцев назад
Hey brother, wonderful video, but I'm having a slight problem with my code. The closer to the sprite my mouse gets the slower it is, the further the faster. Any idea how to fix that? having trouble with it. Using Godot 4 btw
@littleoliveoil
@littleoliveoil 7 месяцев назад
I stumbled across the exact same issue and I'm trying to work through it. I think the method is faulty to begin with as the velocity is determined by calculating the distance between your character and the mouse position. Higher distance means higher velocity, so there is nothing wrong with the syntax itself, it just isn't correct for this application. I'm a beginner too so unfortunately I don't have the solution yet, but will reply when I have found it.
@user-rb4mk6hk9z
@user-rb4mk6hk9z 7 месяцев назад
I actually ended up finding a solution to it, I'll link the video that taught me how below. Honestly i'd recommend checking out more of his stuff too. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-XJw6mhAmDc0.htmlsi=hENRakB4L8fDKtJ3 if the link don't work it's called "How to Shoot a Projectile/Bullet from a Player! || Learn to think like a Professional Game Developer" by coding quest. @@littleoliveoil
@user-rb4mk6hk9z
@user-rb4mk6hk9z 7 месяцев назад
while watching keep in mind some names have changed, mainly position 2D has been changed to Marker 2D.@@littleoliveoil
@arithmetic1938
@arithmetic1938 7 месяцев назад
Make sure to normalize the vector you get inorder to remove the magnitude
@kalpayux7712
@kalpayux7712 3 месяца назад
for some reason in mine it just don't stop shooting
@mohammadirfansuhail8tha548
@mohammadirfansuhail8tha548 2 года назад
Invalid set index 'velocity' (on base: 'node2d') with value type 'Vector2
@arithmetic1938
@arithmetic1938 2 года назад
Make sure you define velocity in the script
@teammerdoss6234
@teammerdoss6234 6 месяцев назад
How to make the bullet rotate to the position of the mouse
@arithmetic1938
@arithmetic1938 6 месяцев назад
You can call look at position plus velocity and it should make the bullet point in the direction it's heading. P.s. when creating the bullet make sure it's pointed to the right while the bullet scene has no rotation
@AdamsAGD
@AdamsAGD 11 месяцев назад
how do you shoot a bullet without using mouse position. im using WASD to move around and just want to use my players vector2 as my bullets.
@arithmetic1938
@arithmetic1938 7 месяцев назад
When I call the mouse position, I'm using that to get a direction vector. You can instead just use the player's velocity
@bobro1005
@bobro1005 3 месяца назад
you probably wont respond but why does my bullet only go right even with all the code? its spawning where it should its just not going anywhere else except right im also using godot 4
@arithmetic1938
@arithmetic1938 3 месяца назад
Made sure to change the velocity and travel direction of the bullet when it spawns
@bobro1005
@bobro1005 3 месяца назад
@@arithmetic1938 ty
@Michael29116
@Michael29116 8 месяцев назад
Why is the position of the bullet not on the player? I need help
@arithmetic1938
@arithmetic1938 7 месяцев назад
Make sure that the shoot point is set where you want it to shoot from, try calling global_position to remove differences in relattive position, and make sure that the players collision layer isn't affected by their bullet
@fabry9354
@fabry9354 2 года назад
I follow all the tutorial but the bullet when add func mouse position doesn't work can you upload this file?
@fabry9354
@fabry9354 2 года назад
Invalid set velocity with value of type vector 2
@arithmetic1938
@arithmetic1938 2 года назад
I ended up loosing the file for this as I didn't back it up, if I find the time I'll rebuild it and toss it on github
@catmist4651
@catmist4651 Месяц назад
I don't expect a response but I can't find Position2D on godot 4.2
@MindSweptAway
@MindSweptAway Месяц назад
It’s now “Marker2D”
@reynold99991
@reynold99991 Год назад
what if i setup a projectile with just area2d sprite and collision shape. How should I code it to achieve the same functionality
@arithmetic1938
@arithmetic1938 Год назад
You would need to manually change the position variable instead of using "move and slide" or "move and collide" that could be something like 'position += velocity × delta' it might need other small changes too depending on the rest of your code
@reynold99991
@reynold99991 Год назад
@@arithmetic1938 actual question is how would you implement the above in 3d (2.5D basically 2d sprite in 3d). I need to lob a dynamite on someone enemies.
@nathanjacobs9658
@nathanjacobs9658 2 года назад
I already had a world scene and it broke my camera, whenever i play i just have a grey empty screen
@arithmetic1938
@arithmetic1938 2 года назад
Interesting, would you be able to send me some screenshots on discord and I'll see if I can locate the issue?
@nathanjacobs9658
@nathanjacobs9658 2 года назад
@@arithmetic1938 ye sure
@dobrealexandru1776
@dobrealexandru1776 2 года назад
My projectiles starts every time from the same spot and my code is exactly like yours....
@arithmetic1938
@arithmetic1938 2 года назад
Make sure you're grabbing the global position of the spawn point and that it's a child of the player. If you want you can also post screenshot in the discord (link in description) and I'll see if I can spot the issue.
@hipxel8918
@hipxel8918 2 года назад
Umm the function shoot() does not exist in my editor
@arithmetic1938
@arithmetic1938 2 года назад
The shoot function doesn't exist be default I show how to make it in this tutorial
@rajshrihirgude8023
@rajshrihirgude8023 2 года назад
i have aproblem when i take the mouse to player the bullet sticks to the player plz help
@arithmetic1938
@arithmetic1938 2 года назад
You might want to make so that the player and bullet are on different collision layers so that the player can't collide with there own bullet. You could also move the bullet spawn a but further from the player to prevent collision on spawn
@aneerudh1712
@aneerudh1712 2 года назад
Are you alive bro? Your Vids are really good. Take care in life there are people who care about you:)
@arithmetic1938
@arithmetic1938 2 года назад
Thanks for reaching out. I didn't mean to scare you or anything, I ended up taking a break to focus on my new job and I was feeling a bit of burn out. Guess the break ended being a lot longer than I had planned.
@lewiathan3704
@lewiathan3704 Год назад
this is a tutorial i neded im a biginer and this tutorial is the only one thet worked i love it and yea there are some glitches in shooting for exemple when bullets colaid they stop and can you make a tutorial to fix it?? thnx by the way
@arithmetic1938
@arithmetic1938 Год назад
As for the bullets collision the fix would depend on what you want to happen. You can make so bullets don't collide with each other. Make then destroy each other, or even make them bounce off of each other
@lewiathan3704
@lewiathan3704 Год назад
@@arithmetic1938 tnx for replaing and about bullets collision i wont to bullets don't collide with each other/Making them destroy each other (thets quet a fast replay bu thw)
@arithmetic1938
@arithmetic1938 Год назад
To make so the bullets don't collide you're going to want to have the bullets on their own collision layer and have the collision mask not have that layer selected. I don't think I really have any videos explaining how collision layers work though. If you want them to destroy when they collide you'll want to add collision detection and have them call queue_free()
@asdepyke2419
@asdepyke2419 2 года назад
it work but the bullet start in the middle and not to my player so if i move and after i m shoot the bullet shoot but the it start shoot at the middle why?
@arithmetic1938
@arithmetic1938 2 года назад
Make sure that when you're setting the bullets position your setting it to the global position. 3:37 I think I cover that
@asdepyke2419
@asdepyke2419 2 года назад
@@arithmetic1938 it works now ty
@makidonz
@makidonz 3 года назад
Спасибо
@arithmetic1938
@arithmetic1938 3 года назад
Glad I could help :D
@Figstuck
@Figstuck 3 месяца назад
How do i make the bullet face the same way as my character tho?
@arithmetic1938
@arithmetic1938 3 месяца назад
If you do a look_at then pass it's position plus the way you want it to look it'll rotate which ever way you want it to
@Figstuck
@Figstuck 3 месяца назад
@@arithmetic1938 thanks!
@duxverseinteractive
@duxverseinteractive Год назад
hello, please can you help me i have an error: Cannot get return value of call to "action_press()" because it returns "void".
@duxverseinteractive
@duxverseinteractive Год назад
Please help
@ghostcomodo
@ghostcomodo 8 месяцев назад
@@duxverseinteractive use "is_action_just_pressed"
@ValidShortking
@ValidShortking 2 месяца назад
How do you delete the bullet after it reaches a certain point or distance
@Aminrexa
@Aminrexa 2 месяца назад
there are different ways you can do that, what I do is that I create a VsibleOnScreenEnabler2D node in my bullet scene, set it up, connect the on screen exited signal to the script and then queue_free() it. the whole process takes about 2-5 minutes you can look it up on youtube
@ValidShortking
@ValidShortking 2 месяца назад
@@Aminrexa I been waiting for you to response, thank you. I know no one asked but im still 15 and im trying to learn as much godot as I can and me and my friends dream game.
@Aminrexa
@Aminrexa 2 месяца назад
@@ValidShortking that's actually a perfect age to start learning game dev, I'm also a beginner still learning Godot and GDScript, just remember making big games takes lots of time and patience, for now keep making smaller projects to both learn new things and improve your skills, don't spend all day watching tutorials, keep working on your project and look up a specific tutorial if you're stuck somewhere, wish you the best
@gamasaurus1226
@gamasaurus1226 10 месяцев назад
Does anyone know how to change teh speed of the bullet?
@arithmetic1938
@arithmetic1938 7 месяцев назад
The bullet script should have a speed variable you can change to change the speed.
@markartist7014
@markartist7014 Год назад
Please explain this if editing for a controller
@arithmetic1938
@arithmetic1938 Год назад
I have another video explaining how to aim with the controller. Everything else should work the exact same
@MadFroggysTech
@MadFroggysTech 8 месяцев назад
Brother how to move the player a step backwards after shooting bullet??
@arithmetic1938
@arithmetic1938 7 месяцев назад
If you take the opposite direction that the bullet shoots (times it by -1) you should be able to times that by a force and apply that to the player. You can also temporarily disable the controls while they're knocked back if you want using a state machine
@MadFroggysTech
@MadFroggysTech 7 месяцев назад
@@arithmetic1938 I did it thanks
@bechirhabbechi3748
@bechirhabbechi3748 2 года назад
Invalid get index 'global_position' (on base: 'null instance').
@arithmetic1938
@arithmetic1938 2 года назад
I would need to see the line that's happening on to give you more, but that means that you're trying to call global_position on a variable that is null
@AeSoGakalololoolmlololoolm
@AeSoGakalololoolmlololoolm 5 месяцев назад
Source?
@arithmetic1938
@arithmetic1938 5 месяцев назад
Sadly I lost the source code for this project
@DyIanGaming
@DyIanGaming 10 месяцев назад
Does anyone know why my code isn’t working I have everything copied down exactly but it isn’t even calling the function
@Mysticscubing
@Mysticscubing 9 месяцев назад
whats the code it could be that instance() is called instantiate() now i had that problem
@arithmetic1938
@arithmetic1938 7 месяцев назад
Sorry, the video is a bit older. Some of the key words might have changed a bit
@DyIanGaming
@DyIanGaming 7 месяцев назад
@@arithmetic1938 yea luckily I combined it with a few other tutorials to make my own shoot code thanks for the tutorial tho
@dailyuser3811s
@dailyuser3811s Год назад
How can I destroy bullet to avoid much memory usage
@arithmetic1938
@arithmetic1938 Год назад
Call queue_free() on the bullet when you no longer need it. Alternatively, you could save unused bullets in an array, so you don't need to reinstance them
@nomaf109
@nomaf109 2 года назад
Why if bullet shoot out of own position2d? It starts from other place
@arithmetic1938
@arithmetic1938 2 года назад
From the question I would assume that you're using the local position instead of the global position, but I would need to look at the code and what it's doing to be sure. Feel free to head over to my discord and post screen shots of your issue if you want
@nally6401
@nally6401 Год назад
The bullet is colliding with my players collision how to I make it so that the bullet doesn't collide with my player but collides with enemies??? Can u pls help?
@arithmetic1938
@arithmetic1938 Год назад
That would be managed using the collision layers make sure that the players collision layer isn't selected in the bullets collision mask
@nally6401
@nally6401 Год назад
@@arithmetic1938 thx bro I've been trying to solve this issue for a while now....kina funny how simple it was
@lego8292
@lego8292 2 года назад
How to doit on c# im try but it gives me error
@arithmetic1938
@arithmetic1938 2 года назад
I haven't used c# in Godot, so I'm not sure I'll be able to help, but you can post screenshots on the discord and I'll try to help when I have time. Alternatively you can ask on stack overflow or the Godot questions form if you can find anything relating to your question
@mintshake8138
@mintshake8138 6 дней назад
move and collide doesnt work
@potatohot656
@potatohot656 11 месяцев назад
when the bullet shoot near postion 2d it speed was slow
@arithmetic1938
@arithmetic1938 7 месяцев назад
The bullet script should have a speed variable you can change to make it shoot quicker
@Roddev776
@Roddev776 4 месяца назад
If mouse is on player the bullet go to the player
@SantiDEV_CR
@SantiDEV_CR Год назад
Why the game closes when I shoot? :(
@arithmetic1938
@arithmetic1938 Год назад
Can't say for sure as I would need to look at your code. You can go ahead and post some screenshots and ask for help in the discord if you'd like
@SantiDEV_CR
@SantiDEV_CR Год назад
@@arithmetic1938 bro i think I already solve it, but thanks for try to help me :)
@Juani_lol
@Juani_lol Год назад
Hey how can i make the bullets dissapear after hitting a wall?
@arithmetic1938
@arithmetic1938 Год назад
add something to check the collision and when it hits call queue_free on the bullet
@kaiyuadachi8070
@kaiyuadachi8070 Год назад
@@arithmetic1938 how can you check for collision if there is no node signal "area entered" on the character2d and even if I add in a area2d it still doesnt work
@havenandaura
@havenandaura Год назад
@@kaiyuadachi8070 Add an area3D around the bullet and set it to detect bodies.
@henryd3bby
@henryd3bby 2 года назад
Hey, sorry if I'm commenting twice, but can you do a tutorial to make this same shooting system but on mobile? Or maybe controller? So that maybe I, could use these in my future games. Anyways, thanks!
@arithmetic1938
@arithmetic1938 2 года назад
I have a tutorial for how to use control input to aim. After watching this and that you should be good to do it on your own. I don't have any good tutorials about anything mobile, but when I searched "Mobile joystick Godot" it pulled up some good videos that helped me in a past project. As always if you get stuck on a particular part of your project. (Even if it's not related to my videos) feel free to join my discord or reach out to me and I'll see if I can help you
@TimberLine534
@TimberLine534 15 часов назад
Hi, I was hoping anyone might know why the bullet wont move? Everything else seems fine. Here's the player's script: extends CharacterBody2D const bulletpath = preload("res://Player/Bullet.tscn") const SPEED = 100.0 const JUMP_VELOCITY = -350.0 var gravity = ProjectSettings.get_setting("physics/2d/default_gravity") @onready var anim = get_node("AnimationPlayer") func _physics_process(delta): if not is_on_floor(): velocity.y += gravity * delta if Input.is_action_just_pressed("ui_up") and is_on_floor(): velocity.y = JUMP_VELOCITY $AnimatedSprite2D.play("Jump") $"Jump SFX".play() var direction = Input.get_axis("ui_left", "ui_right") if direction == -1: get_node("AnimatedSprite2D").flip_h = true elif direction == 1: get_node("AnimatedSprite2D").flip_h = false if direction: velocity.x = direction * SPEED if velocity.y == 0: $AnimatedSprite2D.play("Walk R") else: velocity.x = move_toward(velocity.x, 0, SPEED) if velocity.y == 0: $AnimatedSprite2D.play("Idle") move_and_slide() func _process(delta): if Input.is_action_just_pressed("Shoot"): print("Im shooting") shoot() func shoot(): var bullet = bulletpath.instantiate() get_parent().add_child(bullet) bullet.position = $Marker2D.global_position Here's the bullet's script: extends CharacterBody2D var speed = 1000 func _physics_process(delta): var collision_info = move_and_collide(velocity.normalized() * delta * speed)
@kharl4118
@kharl4118 2 года назад
having a problem on shoot{}
@arithmetic1938
@arithmetic1938 2 года назад
It's supposed to be parentheses () not curly braces {}
@thedigitalwolf6932
@thedigitalwolf6932 Год назад
help, im having problems with parenting i think because im using a gun instead of the player and the bullets are following me... oh and they aren't spawning where they are supost to
@thedigitalwolf6932
@thedigitalwolf6932 Год назад
wtf, changing from global_position to position fixed it, great. Well, actually it will follow the player, so, help again...
@thedigitalwolf6932
@thedigitalwolf6932 Год назад
what if I set the bullet position inside the bullet in a ready func? will that work?
@arithmetic1938
@arithmetic1938 Год назад
The bullet is moving with the player because it's a child of the player. Make sure to set the bullet as a child of the players parent
@thedigitalwolf6932
@thedigitalwolf6932 Год назад
@@arithmetic1938 so I just do get_parent 2 or 3 Times then with add Child?
@arithmetic1938
@arithmetic1938 Год назад
@@thedigitalwolf6932 that's totally dependent on your scene tree. If your gun is a child of the player 2 times, if your gun is a child of something that's a child of the player 3 times
@brunomoreno3666
@brunomoreno3666 2 года назад
How do you do $Position2D in c#?
@arithmetic1938
@arithmetic1938 2 года назад
I can't say for sure as I haven't used c# but that's just a shortcut for the get node function, so probably something like this `GetNode("Position2D")`
@brunomoreno3666
@brunomoreno3666 2 года назад
@@arithmetic1938 thanks for your response :)
@brunomoreno3666
@brunomoreno3666 2 года назад
@@arithmetic1938 i found out how its (GetNode("ChildNode") as Position2D).GlobalPosition;
@arithmetic1938
@arithmetic1938 2 года назад
Glad you were able to find that. I wish you luck on the rest of you project 😄
@ZiRR0
@ZiRR0 2 года назад
how to create a wait time
@arithmetic1938
@arithmetic1938 2 года назад
The timer node is probably the easiest way. If you want a function to pause you can use a yield and have it look for the timeout. If you have more questions feed free to reach out on discord and I can send you some screenshots docs.godotengine.org/en/3.0/classes/class_timer.html
@ZiRR0
@ZiRR0 2 года назад
@@arithmetic1938 already found a one-line solution, but thanks anyways!
@yimiyyussef
@yimiyyussef Год назад
There is a problem with this code though. For a platformer game if you make the gun shot a child of the player and if you move the player while the shot is being processed, you could push or pull the shot. For example if you shoot left and player goes right the shot will also get dragged right while it is shooting left because it is a child of the Player. All this stuff has to be done on the world scene.
@arithmetic1938
@arithmetic1938 Год назад
Well yes if you add the bullet as a child of the player it'll move with the player, whether platformer or not. That's why I had it call the parent of the player node and add it as a child of that in the video.
@arithmetic1938
@arithmetic1938 Год назад
If you add all of the code that needs to spawn stuff into the world scene you're going to end up with very messy code that's hard to work with
@yimiyyussef
@yimiyyussef Год назад
@@arithmetic1938 Yeah I tried that, but since its on the player node script it has no parent. Atleast thats the error I got and had to move my code to the world script.
@arithmetic1938
@arithmetic1938 Год назад
Unless it's the root of the scene then it'll have a parent. Aka, if anything isn't a child of the player then the player has a parent
@disiiidesign
@disiiidesign Год назад
For some reason, I don't even get a bullet. Godot 4 Mobile
@arithmetic1938
@arithmetic1938 7 месяцев назад
Oh, this video is quite an old one, I'm not sure how well it'll work with Godot 4
@Mohamed_abdalrahman
@Mohamed_abdalrahman 3 месяца назад
ممكن كود
@Red_Eagle
@Red_Eagle 3 года назад
First again
@arithmetic1938
@arithmetic1938 3 года назад
Nice, you're good.
@Kilogya
@Kilogya 2 года назад
I dare you to put your mouse on your player, then shoot.
@arithmetic1938
@arithmetic1938 2 года назад
I don't have this games file anymore
@Kilogya
@Kilogya 2 года назад
@@arithmetic1938 You should use an Area2D or something else. The body node you used has collision physics, and there is a bug in the code that allows the bullet to reverse and shoot at the player instead. I just make the bullet go one direction from the bullet script, give it a max range, then set it's position and rotation relative to the player. But I'm fairly new to Godot so maybe there's a better way. Aside from the small bug, you did great and I'd love to see more!
@arithmetic1938
@arithmetic1938 2 года назад
Oh, that's good to know. You could make so that the bullet and player are on different collision layers if you don't want them to affect each other. I think with this one I ended up basing the way to bullet shoots off of it's spawn position when I should've done it off of the players center position so that it always shoots away from the player
@elishavrieling7607
@elishavrieling7607 Год назад
I want to like this video so badly but it has 420 likes.....
@arithmetic1938
@arithmetic1938 Год назад
A true man of culture
@17001045jv
@17001045jv 2 года назад
Bullet code?
@arithmetic1938
@arithmetic1938 2 года назад
Sorry, I didn't end up making a GitHub of this one and I no longer have the code
@thewolf-vm8hm
@thewolf-vm8hm Год назад
Я почесал яйца
@disiiidesign
@disiiidesign Год назад
Понятно
@TimberLine534
@TimberLine534 4 месяца назад
Does anyone know why the game freezes when I click and crashes when I press any other button? Here's the code: extends CharacterBody2D const bullet_path = preload("res://Scenes/bullet.tscn") const SPEED = 150.0 const JUMP_VELOCITY = -350.0 # Get the gravity from the project settings to be synced with RigidBody nodes. var gravity = ProjectSettings.get_setting("physics/2d/default_gravity") func _physics_process(delta): # Add the gravity. if not is_on_floor(): velocity.y += gravity * delta # Handle jump. if Input.is_action_just_pressed("ui_accept") and is_on_floor(): velocity.y = JUMP_VELOCITY $JumpSfx.play() # Get the input direction and handle the movement/deceleration. # As good practice, you should replace UI actions with custom gameplay actions. var direction = Input.get_axis("Left", "Right") if direction: velocity.x = direction * SPEED $AnimatedSprite2D.play("Run") if direction == -1: $AnimatedSprite2D.flip_h = true else: $AnimatedSprite2D.flip_h = false else: $AnimatedSprite2D.play("Idle") velocity.x = move_toward(velocity.x, 0, SPEED) if not is_on_floor(): $AnimatedSprite2D.play("Jump") func _process(_delta): if Input.is_action_just_pressed("ui_accept"): shoot() $Node2D.look_at(get_global_mouse_position()) func shoot(): var bullet = bullet_path.instance()
@abhirammakesgames
@abhirammakesgames 4 месяца назад
You should put instantiate()
@ihydd
@ihydd Год назад
bullet.position = $Node2D/Position2D.global_position bullet.velocity = get_global_mouse_position() - bullet.position on this line it says "Invalid set index 'velocity' (on base: 'Node2D') with value of type 'Vector2'."
@arithmetic1938
@arithmetic1938 Год назад
You need to make sure that the bullets script has a velocity variable with the type of Vector2
@volcano3864
@volcano3864 2 года назад
Invalid get index 'global_position' (on base: 'null instance').? oh i was putting the position 2d in the bullet thanks it worked
@arithmetic1938
@arithmetic1938 2 года назад
Glad I could help
@servercraft17
@servercraft17 Год назад
Great tutorial but how do I make it not spawn hundreds of bullets when the shoot button is held down? I only modified one thing so it would work with buttons Ill shoo the line of code below bullet.velocity = $Target.global_position - bullet.position Target is a Position 2D node that is farther out in front of the player.
@arithmetic1938
@arithmetic1938 Год назад
I think in my tutorial I had it check if button was just pressed, you're probably having it check if the button is currently pressed (aka mine was one bullet per click) if you want the player to be able to hold the shoot button, you're going to want to make so it'll only shoot 1 bullet per x time. I would have a boolean variable that is called something like can_shoot. And a timer node called shoot speed. Probably one shot no auto start. Have the shoot function check if can_shoot is true at the very start. If it's not return After that if statement set can_shoot = false and start the shoot speed timer node. Then connect the timeout signal from the shoot speed timer node to the script. (Any function name should be fine you can leave it default _on_shoot_speed_timeout or something like that) In that function set can_shoot to true. You can also do something similar with reload just have another timer with a bit of a longer time. Make sure to have an ammo count and check if ammo is greater than 0 if not return have a button start reload timer and animation. And have timer set to a function that resets the ammo count. (Few more steps if you want the user to not have infinite reloads) just make sure not to forget to subtract from the ammo count with each shot
@servercraft17
@servercraft17 Год назад
It worked! thank you!
@ifandor1
@ifandor1 Год назад
I share a solution that I found to a problem I did to myself, if anyone needs it! I use a shotgun as a gun, and being the barrel of the shotgun really long, the player could "shoot behind the point of the gun" basically shooting himself, the solution is to take that into consideration at the moment of giving velocity to the bullet: var shotgun_barrel = $Pivot/Position2D.global_position - $Pivot.global_position bullet.velocity = get_global_mouse_position() + shotgun_barrel - bullet.position
@arithmetic1938
@arithmetic1938 Год назад
Thanks for sharing 😊
Далее
Splitting a Bullet - Godot Tutorial
9:07
Просмотров 4,3 тыс.
BETTER 2D visuals in 7 EASY TIPS
10:38
Просмотров 63 тыс.
We made Vampire Survivors BUT in 10 Lines of Code
7:08
50 YouTubers Fight For $1,000,000
41:27
Просмотров 121 млн
Top Down 2D Shooting in Godot
18:33
Просмотров 82 тыс.
What size should your assets be? | HD 2D GAME ART
12:10
How Games Make VFX (Demonstrated in Godot 4)
5:46
Просмотров 323 тыс.
Chess on a Massive Board
9:47
Просмотров 19 тыс.
Complete 3D Shooting Mechanics - Godot 4 FPS Tutorial
12:14
NOT STOPPING TIL NEW WORLD RECORD
9:37:15
Просмотров 2,3 млн
NOT STOPPING TIL NEW WORLD RECORD
9:37:15
Просмотров 2,3 млн