Easy Look At Mouse Script in Godot - Godot Quick Tips

  Рет қаралды 24,360

Code with Tom

Code with Tom

Күн бұрын

In this super quick godot tutorial I will teach you how to make a node look at the current mouse position.
For more quick godot tips and tutorial, click that subscribe button and notification bell.
Music By: LAKEY INSPIRED @ / lakeyinspired

Пікірлер: 66
@uheartbeast
@uheartbeast 5 жыл бұрын
Cool series :) I look forward to more.
@CodeWithTom
@CodeWithTom 5 жыл бұрын
Thank you so much man 😁
@popadom4529
@popadom4529 3 жыл бұрын
@HeartBeast @CodewithTom how do you look away from mouse
@reymarckessaguirre5082
@reymarckessaguirre5082 3 жыл бұрын
@@popadom4529 first, try to get the position of the mouse with get_global_mouse_position(). Then, store it in a Vector2 variable. After that, use the function var lookingAwayFrom = Vector2(get_global_mouse_position()) var lookingAt = -lookingAwayFrom func _process(delta): look_at(lookingAt)
@reymarckessaguirre5082
@reymarckessaguirre5082 3 жыл бұрын
@@popadom4529 i am not sure about my solution, but it only takes a few seconds to try, nothing much to lose.
@popadom4529
@popadom4529 3 жыл бұрын
@@reymarckessaguirre5082 Thanks
@mitchellmiller3843
@mitchellmiller3843 2 ай бұрын
Exactly what I was looking for. Thank you for the quick and simple explanation!
@aZaamBie135
@aZaamBie135 4 жыл бұрын
Thanks so much! I never knew it was that simple.
@CodeWithTom
@CodeWithTom 4 жыл бұрын
You're very welcome.
@lonewolfenock3527
@lonewolfenock3527 4 жыл бұрын
Simple and to the point. Subbed.
@dejo095
@dejo095 4 жыл бұрын
Hey this is awesome stuff! you got yourself another subscriber buddy 😁
@pietertalens1256
@pietertalens1256 3 жыл бұрын
Great video! I'd love to see how someone might incorporate this with an isometric sprite with 8 directions. Do you think you could make such a video?
@Goleko420
@Goleko420 4 жыл бұрын
How do you do this in 3D though? I've been trying over and over and cannot get this accomplished
@ovaldreamx4397
@ovaldreamx4397 4 жыл бұрын
Very usefull!! Some ideas for next episodes could be shooting things, draw vectors of the body on screen and spawners
@ovaldreamx4397
@ovaldreamx4397 4 жыл бұрын
just subbed btw
@xyonblade
@xyonblade 3 жыл бұрын
So here's a question, I got a scene working fine where I have a sprite looking at the mouse, but now I've instanced that scene onto a player scene three times, and now the sprite that was instanced is not looking at the mouse, I'm guessing it has something to do with only the scene being played having an active _process function? If I wanted to have multiple instances of say, a turret that are attached to the player, is it possible setting up a script or something on the original scene that then works when you instance it onto the player?
@malinduumeshan3119
@malinduumeshan3119 4 жыл бұрын
I switched unity to godot 2 weeks ago.I remember I wrote 4-5 lines of code to do the same thing in unity with C#
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Gdscript is a very powerful and succinct language 😁
@xyonblade
@xyonblade 3 жыл бұрын
I have been looking specifically for this for a while, forgot how to make weapons systems "look" at the mouse which might not be where the player is moving, this should help solve that problem. :D
@yourkodi3945
@yourkodi3945 4 жыл бұрын
Its crazy how this is and if you compare it to the same code in Unity, the godot version is sooo simple compared to unity version (well look at mouse code at least!)
@RedcodeSg
@RedcodeSg 4 жыл бұрын
Thanks, this is really useful.
@CodeWithTom
@CodeWithTom 4 жыл бұрын
You're very welcome 😁
@mina7572
@mina7572 3 жыл бұрын
What about launching a spawned objects in a straight line, towards the cursor?
@champhenryduco4651
@champhenryduco4651 4 жыл бұрын
thank you please keep this up
@FrancoisSchnell
@FrancoisSchnell 5 жыл бұрын
Great serie idea, keep it up! :)
@CodeWithTom
@CodeWithTom 5 жыл бұрын
Cheers Francois
@aamir2694
@aamir2694 3 жыл бұрын
@@CodeWithTom thank you very much
@NeZversSounds
@NeZversSounds 4 жыл бұрын
WOW, awesome!
@coconurt7153
@coconurt7153 2 жыл бұрын
How can I get in an if statment that under a certain angle(when the mouse Is pointing uowards, so at the back of my player) the line has to be invisibile?
@TheTaxicomics
@TheTaxicomics 3 жыл бұрын
Thanks a bunch!
@DexonRax
@DexonRax 3 жыл бұрын
Man you are genious
@diasdasilva5096
@diasdasilva5096 Жыл бұрын
i have a sprite of a bow and i want it to look at the mouse but it never looks right: the mouse can be somewhere and the bow will be pointing elsewhere(also my game is a platformer). please help me fix it
@thoaihoquang1578
@thoaihoquang1578 2 жыл бұрын
But how to get the mouse position in vector3 and Vector2 like x,y or z
@lorenzoguzzo1354
@lorenzoguzzo1354 4 жыл бұрын
great video really useful
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Really glad you found it useful Lorenzo!
@jonus5331
@jonus5331 3 жыл бұрын
I was trying to do this by calculating vectors and using arc cos...
@user-qc1mc2ly8j
@user-qc1mc2ly8j Жыл бұрын
My character rotates slightly away from the mouse, any idea as to why?
@valentas000
@valentas000 3 жыл бұрын
How to Clamp that Rotation ? Can you add Code 2 that
@calebross6052
@calebross6052 4 жыл бұрын
Hey, when I do this the player looks at a position that is on the left of my mouse, instead of directly at my cursor. Do you know how to fix this?
@calebross6052
@calebross6052 4 жыл бұрын
Nvm, it was the way my sprite was facing :(
@zelef2502
@zelef2502 3 жыл бұрын
I like it !
@trakinado2564
@trakinado2564 Жыл бұрын
cool but you dont really need the func process delta in the script to it work
@mrsupertash
@mrsupertash 3 жыл бұрын
How do I change the position the sprite is facing? For example a rocket ship would be facing up when I import the asset. Do I need to import it sideways or add a rotate 90° method somewhere so that the top is facing the mouse and not the right side. What is best practice here?
@Zombozy
@Zombozy 3 жыл бұрын
Assuming you'd like the tip of your rocket to face the mouse cursor you would make it drawn horizontally, with the tip facing right. I had the same exact issue, except with a sword. Here's an example with a sword: -|========> After flipping my sprite like that, as opposed to having it straight up, it works perfectly. (hope my really cool sword picture helped)
@mrsupertash
@mrsupertash 3 жыл бұрын
@@Zombozy Thanks, the sword picture is excellent! Yeah, I mean that seems to be the intuitive workaround. I'm just wondering because I couldn't find in the Godot docs anywhere that the right side is the face. Since that is apparently what's happening, it should be stated somewhere and also why to know how to handle this best. When I look at tile sets on itch.io for example things like spaceships would be facing up, not to the right. I can't imagine the best way to handle this is to flip every single asset 90 degrees before being able to use these.
@nhnova1452
@nhnova1452 3 жыл бұрын
thank you
@Eireguy_
@Eireguy_ 3 жыл бұрын
thanik you, im making a shooter game :)
@JoseRoberto-wt8vz
@JoseRoberto-wt8vz 2 жыл бұрын
Muito obrigado, funcionou perfeitamente!
@applebeestacos4840
@applebeestacos4840 3 жыл бұрын
Can you make a Undertale/Earthbound like RPG in godot? (With gdscript)
@mistadude
@mistadude 3 жыл бұрын
Of course (sorry for the late comment)
@BeSerious.studio_official
@BeSerious.studio_official 27 күн бұрын
how can you do this in multiplayer?
@DineshYadav-iv5jo
@DineshYadav-iv5jo 3 жыл бұрын
Thanks
@techofhappiness395
@techofhappiness395 4 жыл бұрын
It was awesome. Can we use this code for touch screen controller ?
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Good question, I haven't actually tried :)
@techofhappiness395
@techofhappiness395 4 жыл бұрын
@@CodeWithTom Try and Get Success ❤️
@popadom4529
@popadom4529 3 жыл бұрын
Does anyone know how to look away from the mouse?
@devinbelver7124
@devinbelver7124 3 жыл бұрын
technically you can just rotate or flip the visual so the back of the node is "looking at" the mouse
@justash123
@justash123 2 жыл бұрын
well and thats how you create a masterpeice
@oghene2778
@oghene2778 2 жыл бұрын
Me over here thinking you need to use schrodinger's equation to find the superpostion of the mouse then use entropy to calculate the total efficiency of the keyboard before dividing it by 0: This guy writing 2 lines of code:
@beeshings
@beeshings 9 ай бұрын
Bro what?! This sh*t would take a whole afternoon to make properly in Unity... In Godot it's ONE LINE.
@interrobang9515
@interrobang9515 3 жыл бұрын
when half the video is advertising
@ClipSaam
@ClipSaam Жыл бұрын
wtfff its just!!!!
@samangolahmadi2710
@samangolahmadi2710 9 ай бұрын
1 line of code 2 mins of talking
Raycast Weapons in Godot - Make an FPS in Godot Part 2
29:00
Code with Tom
Рет қаралды 57 М.
Godot Recipes: Animation States
10:31
KidsCanCode
Рет қаралды 105 М.
БОЛЬШОЙ ПЕТУШОК #shorts
00:21
Паша Осадчий
Рет қаралды 11 МЛН
Ray-casting from the screen : Look at the mouse in 3D [GODOT]
6:37
choosing a game engine is easy, actually
15:08
samyam
Рет қаралды 351 М.
Top Down 2D Shooting in Godot
18:33
Code with Tom
Рет қаралды 82 М.
Loops, Signals, get_node & call_deferred in GDScript
14:44
Code with Tom
Рет қаралды 18 М.
I made a game using Godot for the first time
7:35
shawcat
Рет қаралды 1,1 МЛН
Godot Shader Tutorial [Basics] in 7 minutes
7:47
Master Albert
Рет қаралды 88 М.
Godot's 5 Scripting Languages: Which Should You Use?
10:42
GDQuest
Рет қаралды 133 М.
BETTER 2D visuals in 7 EASY TIPS
10:38
MrEliptik
Рет қаралды 63 М.
When Your Game Is Bad But Your Optimisation Is Genius
8:52
Vercidium
Рет қаралды 1,4 МЛН