Godot: Raycast2D not casting to correct position - godot

I have a raycast2d node that I want to cast to where the player clicks, but when I click it still casts but not to the right place.
My code is just $RayCast2D.set_cast_to(fire_position), fire_position being where the mouse clicks.
Can anyone help?

The RayCast2D expects a vector on its own local coordinates.
Presumably you got the position of the mouse click in global coordinates. Then you would convert it to the local space of the RayCast2D like this:
$RayCast2D.set_cast_to($RayCast2D.to_local(fire_position))
I'll also remind you that if you are updating raycast and checking it right away, without a physics frame passing, your will have an stale result. To fix that you can call force_raycast_update on it.

It sounds like the issue may be with how you are determining the 'fire_position' variable. Without more information about how that variable is being set, it's difficult to me sayed for certain what the problem is.
However, you can try to debug the issue by printing out the 'fire_position' variable to the console before passing it to the RayCast2D.set_cast_to() method, to check if it's the correct position where the mouse clicked. Also, make sure that you have set the correct orientation of the RayCast2D node, so it is pointing in the direction you want to cast the ray.

Related

FLTK's Fl_Scroll - run code in reaction to scrolling happening?

I am using FLTK 1.3, displaying a single Flex column with a number of Flex rows inside a Fl_Scroll. I want to do something to rows that were outside of the visible area when they scroll into view. But I cannot figure out how to do that. There is no event emitted when the scroll position changes (as far as I can see) nor does a callback on the scroll seem to do anything.
The only solution I can think of is something like using the column's, scroll's, or window's callback to get informed of all UI events (such as move, key up, leave, ..) and use them to check whether the scoll's yposition has changed from the last time and run the code I need if it is....
But there surely must be a better way?
Thank you!!!

Blender : Some objects disappear when I turn to camera mode (it's not the snapping I think)

OK... here is the thing...
I am modeling a Star Wars Cruiser.. I'm doing pretty fine, but.. whenever I look through the camera, half of my ship disappears ?! Now you might think it's the clipping, but that doesn't make sense, since the clipping is set to 0,1 mtr - 10.000 mtr, which should be more than enough. Besides that, the clipping is the same for both the visible and now disappeared objects...
Does anyone have any clue ?
I also tried to change the Local view to Global view.. but no dice...
Here is a screenshot in not-camera view :
And here is one in camera view : i.imgur.com/XaxAHIN.png
I'm using Blender 2.82
Please let me know if you need more info or even a link to the model...
OK, I got some help from a friend... Joshua Rooijakkers from the Netherlands...
He fixed the problem in seconds...
So ... it WAS the clipping.. the setting was just buried somewhere I didn't look...
Thanks Josh ! :-)
Objects disappear in camera view modeWhile setting up my camera with the camera lock to view option selected, I noticed that on switching on to the camera view, the object had disappeared.
I tried zooming in and out, but that did not work. I exited the camera view and then selected the object in the outliner and then tried zooming in and out and then panning down and adjusting the view in the view port. I could see that the object was now visible and that the camera was positioned below the object. That was because the camera was added wrt to the position of the cursor which was snapped to the world origin. I a sure many would have encountered such issues.
I then selected the camera to ascertain its position. Then by using the grab tool, I moved the camera along the Z axis just above the object and then switched to the camera view and selected the lock camera to
view option to adjust the camera view to the desired position.
This helped me locate my object in the camera view. Do let me know in the comments if there are other ways of dealing with this.

How do I do gtk mouse interaction correctly with Haskell Chart library?

I'm using this library
As of now I have a point that follows the mouse, but it only kind of works because I assume the window will be 500x500, and the point is never directly behind the mouse because (0,0) on the graph is not (0,0) on the window.
If I could just figure out what the graph origin is relative to the window's coordinates, then I could fix everything, but I can't seem to figure out how to do that. Graphics.Rendering.Chart.Renderable seems relevant, such as the "Pick Function" and RectSize, but again I'm not sure how to actually get anything relevant from it. Graphics.Rendering.Chart.Backend may also be relevant.
Or this may actually be something to solve with gtk? I don't know.
Please help, this has been killing me.
EDIT: Here's my current code if it helps

Graphics - refreshing just one object

With my friend we are trying to make some game. When we draw a grid or checkerboard and then move objects by arrows, "panel.Refresh();" refresh all the objects, obviously the complete panel. Can we somehow refresh just that objects, which are supposed to move? We tried to make two panels. First panel generates the grid and the second one generates the object which is supposed to move, but when the object moves, the panel with the grid blink whenever the panel with object takes refresh. Can someone help us please? Thank you so much.
You should try to add some code so anyone can help you. By just your text we can hardly get a glimpse of what you want and mean. Try to create a small compiled program that works like the problem you are posting here with only what is strictly needed to reproduce your problem and post the source code here.

How to write an X11 app that follows the cursor

I'd like to write a Linux screen magnifier that's customized to my liking. Ideally, the magnified window would be a square about 150 pixels wide that follows the mouse cursor wherever it goes.
Is it possible to do this in X11? Would it be easier to have an application window that follows the mouse around, or would it be better (or possible) to forget about the window altogether and just make the mouse pointer a 150x150 square that magnifies whatever's underneath?
Look at the source to xeyes?
This actually already exists, it's called Xmag (do a Google search for additional info). You might want to check out the source code for it if you want to know how it works.
EDIT: looks like I misread your question a little bit... if you want a magnified square to follow the mouse pointer around, I suppose it should be possible, but I don't know the technical details of how you'd do it. Regardless, the place to start is probably by looking at Xmag as a starting point.
I am unsure if this can run as its own app or would have to be integrated into your window manager. Either way, you would need libx11 (might have a different name from distro to distro). Also, I would suggest taking a look at swarp. I know this is not even close to what you are talking about, but the source code is only 35 lines and it shows what can be done with libx11.
I would personally make that a frameless window that always stays atop with a 1px hole in the middle. The events that the user makes (Mouse clicks, keypresses, whatever) is passed to the window below.
And when the user moves it's cursor it is ought to be visible to your window and you just move it over a bit. For the magnifying part, well - that is left as an exercise to the reader (Because I do not know how to do that as of yet ;-).
Texworks comes with such a feature to inspect the pdf resulting from typesetting a latex source. You can also choose between a square or a circular magnifier. See https://www.tug.org/texworks/ for access to the code which can serve a launchpad.

Resources