1/25/2024 0 Comments Godot raycast![]() Should give you the direction for the ray that goes toward the mouse_pos, given the camera projection and Viewport size. Pay attention to project_ray_origin and project_ray_normal. $Ra圜ast.cast_to = camera.project_ray_normal(mouse_pos) * ray_length $Ra圜 = camera.project_ray_origin(mouse_pos) Var mouse_pos = get_viewport().get_mouse_position() To make it follow the pointer, you can do this: var ray_length = 100 # some large number If you can't - or rather not - depend on pickable objects, but still have something to collide with, you can use a Ra圜ast node. Then connect the input_event signal or override the _input_event method, where you will get - among other parameters - the position in 3D of the pointer when it is over the 3D object. the board), you can set input_ray_pickable to true on it. I'm not sure I understand your limitations, so I will give you a few approaches, and hopefully this gets you to the solution along the way. I'm very new to game development and the techniques overall, any help and pointers how to best achieve the task are greatly appreciated! The Camera's project_position ( Vector2 screen_point, float z_depth ) method doesn't seem to be a viable choice either, as my camera should be able to rotate around the board freely and not be locked in the top-down view (otherwise this method would be the perfect solution, to my understanding?). I was unable to find a Node type to use as an infinite plane for ray collision. I can't, however, rely on the board, as the game board itself is floating in a "void" and coordinates around the board should be detectable (and game-wise illegal). Because the entire game happens on a plane, I'm not concerned with the Y axis - I just need to raycast from my camera, through the mouse cursor, onto the world plane and acquire the (x, 0, z) coordinates. As such, I need to frequently transform my viewport's mouse coordinates into world coordinates to move the pieces. finding a position on a texture) or the problem was caused by something else and the solution didn't apply. Vector3.I've been trying to find a solution to this task and despite finding answers to similar issues, they were always somewhat overcomplicated (e.g. I have the cast_to Vector (which is a static Vector and this is good) and of course the global_transform of the Ra圜ast Node itself, but how do I get it's global view direction out of this information since I struggle to find a function like However I struggle in getting the global pointing vector of my Ra圜ast. avoid misplacement of 2 independnet Position3D which will result in a faulty view vector.So far so good, but I think using Ra圜asts here would be more appropriate because: Var child_dir: Vector3 = child_root.global_transform.origin - child_tip.global_transform.originĪfterwards I calculate the Angle between both vectors ( Vector3.angle_to()) and then slowly rotate the child_dir Vector towards the look_at_dir Vector I utilize the global_transform.origin of all 4 Positions to calculate 2 Vector3 like so: var look_at_dir: Vector3 = look_at_root.global_transform.origin - look_at_tip.global_transform.origin I have 2 Ra圜ast attached to two separately moving Nodes, one is controlled by the camera and therefore transformed by the mouse input and the 2nd one is attached to a moving part of my Player which I want to smoothly rotate towards the view direction of the camera.Įg: I have a Mech which a moveable head which should smoothly rotate towards the current camera view angle.Ĭurrently I have 4 Position3D in my Scene which describe the root and tip of the camera view direction and the root and tip of the mechs head view direction. HDRI Haven – CC0-licensed panorama skies.CC0 Textures ⋅ ⋅ Texture Haven – CC0-licensed PBR materials.Godot Shaders – Shaders specifically made for use in Godot Engine.Awesome Godot (curated list of Godot resources).Twitter Read before posting: Frequently Asked Questions Community Platforms Discord Contributors Chat Support Godot development on Patreon! Reference material. ![]() A community for discussion and support in development with the Godot game engine.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |