How can I make aiming with a raycast more forgiving?

4.4.1

I’m making an FPS with a grappling hook mechanic. The grappling hook uses a raycast and checks if its colliding with anything and pulls the player to that point. The problem is that its really hard to aim if you’re going a little fast. How would I check for a point near where I’m aiming and make that the point my player grapples to, even if the ray doesn’t touch it?

Just throwing an idea out, try to give the grapple point an area node with a “forgiving sized” collision shape. You have to configure your raycast to be able to interact with areas in the inspector window.

       Var collider = raycast.get_collider()
        If collider is Area#(2D/3D) whichever...
          #collider.grapple_and_swing()
2 Likes

I’ve thought about doing this, but would it it cause performance issues if i had a lot of grapple points in a scene?

Only one way to know that. Make it and run the profiler on your target hardware. No use in guessing.

Physics engines are well optimized nowadays. The cheap broadphase detection can efficiently handle a large number of colliders.

1 Like

You can use a ShapeCast with a sphere, make sure you have a specific collision layer/mask for it to interact with only the objects you want.

3 Likes

Performance issues in Godot typically crop up when people are making thousands or tens of thousands of things. If you have 10,000 grapple points in a level, you should either make smaller levels or chunk the level. But if you’re trying to do something like the Spiderman game, you shouldn’t be using grapple points at all.

Yeah if you need to be able to attach anywhere, best to use shape casting, or scatter multiple raycasts across some solid angle or inside a cylinder.

1 Like