#Flashlight Not Really Following Cursor

1 messages · Page 1 of 1 (latest)

elder bridge
#

I'm currently working on a segment for a game where you have a flashlight and need to guide it around your environment with the cursor. However, though after many hours I have managed to somewhat get this to work, the results are extremely offset from where they actually should be. Any recommendations?

Note: The code is under _physics_process, and its set to collide with a area body about 50 meters away from the camera

elder bridge
#

Alright, just did a test and putting the flashlight in the center of the camera actually produced basically no different. There was a slight improvement of location, but like only a few pixels

#

Using get_viewport().get_mouse_position() instead of DisplayServer makes it much much better though, even if it’s still not perfect

arctic brook
#

what is the exact intended behavior you’re looking for? do you want the flashlight spot to be exactly where the cursor is at all times?

elder bridge
#

Yes

#

I think getting my collision to work properly will fix it after doing a minor test just now

arctic brook
#

yeah i was thinking you need the wall collisions to be a factor for the behavior to work as intended

latent hazel
#

So I was trying to describe this yesterday but now I have a more physical metaphor.
Imagine a 2d side view of the situation with a piece of notebook paper sideways. Your eye is in the middle of the left side, your flashlight at the bottom left corner. Lay a pencil down on the piece of paper as an obstacle in the scene.
You can move your finger on the right side of the paper (the mouse), and draw a line from eye to finger; where it intersects the "obstacle" is where you want the flashlight to focus iiuc? No solution but to fix the raycasts to work correctly, if so

elder bridge
#

God 😭 so this all comes back to my day one issue of my grid maps just not having collision

#

This is the tree for my gridmaps mesh library, any thoughts as to why this doesnt work?

arctic brook
#

i’m not familiar with gridmaps, but always check the collision layers and masks are set appropriately

elder bridge
#

First thing I did lol.

#

All ray casts (and the raycast for the flashlight) are set to mask 2, and the grid maps to layer 2

arctic brook
#

can you try printing the result of your raycast when you click on a wall?

#

like, is the result always null?

elder bridge
#

Not always

arctic brook
#

does it print the wall you were expecting?

elder bridge
#

No: it’s hitting the occasional collision objects I hid in the walls so the player couldn’t clip through them

#

But, I don’t have them everywhere since the movement system means there’s places the player can’t reach

latent hazel
#

🤔 collision surfaces you're not using are cheap enough (discarded early by broad phase)

#

I think it's false economy. Make solid things solid.

arctic brook
#

they’re trying to make the walls solid, it’s not registering though

elder bridge
#

I think the only thing I’m worried about is having to spend the time placing them everywhere, as silly as that sounds

latent hazel
#

Are they? The way I read their response, solid things are intermittently solid 🙂

#

If you model things in blender, during import if the object is named -col it will handle it for you

elder bridge
#

So I had to resort to second hand collision

arctic brook
elder bridge
#

Some walls, no floors

#

Only walls the player has a chance of walking through

latent hazel
#

Which iiuc is not all walls the player can look directly at, right?

arctic brook
#

oh your walls will all need collision objects if you want the raycast to register them

latent hazel
#

Like myst or smth, with discretized steps?

arctic brook
#

don’t worry too much about optimizing collision objects until it’s a concern. right now you want to get a solution working first

elder bridge
#

Filling everything with collisions works! Now to spend the rest of the day doing that

arctic brook
#

awesome! glad to hear we have progress!

elder bridge
#

Just listing an update here: I solved the problem with my grid map collision! Turns out changing the collision of the grid map itself does nothing, and I actually needed to changed the collision of the static body resource that I exported to the mesh library in order for it to work as intended