better alternative to using look_at(raycast.get_collisionpoint) for third person shooter projectiles

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By witch_milk

background: in my third person shooter i have a ray cast that comes from the camera and serves as the direction that a projectile should travel to. A projectile is instanced at the end of a gun and I use the look_at function to get the projectile to face the direction of the collision point of the ray cast.

the problem is that because my camera is slightly above the player, quite often the projectiles fall short and hit the ground before hitting their targets. I know why this happens and it’s because of the look_at function, this function is making my projectiles look towards the ground too sharply. Overall, this system is great for a first person shooter but not so good for a third person shooter where the camera is offset or above the player, which means to look in front of myself In the game, I have to look down slightly which causes this problem. Moving the ray cast higher or lower means that the ray-cast no longer accurately points towards the cross hairs at the center of the screen.

I don’t see why the look_at() function is the problem, its just making the bullet point at the raycast. The raycast position is the problem isn’t it? +1, by the way, because I really want to know how to handle 3rd person shooting.

Millard | 2020-11-05 15:46

I tinkered with it some bit, and got rid of the ray cast offset and had it be in the direct center of the camera and in front of the player slightly. I used to have this. It works better now. I cannot complain, it does indeed work

witch_milk | 2020-11-05 16:30

My question about raycasts has always been: Doesn’t It look like the bullet is going the wrong direction? I get that in third person, the camera is never lined up with the player and thus the bullet must be going a different direction than the gun is really pointing, but how do you make it look natural?

Millard | 2020-11-05 17:02

do you mean make the player mesh rotate with the direction of the ray cast? in my game the player rotates towards the the direction of the raycast( or camera) when the fire button is pressed, so that it looks natural.

witch_milk | 2020-11-06 21:28

thats a good way to do it, but I noticed that in a lot of third person or first person games, if you look closely the gun model is not pointed where the bullet is going. It’s close, but usually angled to the left or right. I believe that this is to make it so you can see more of the gun, but I have no idea how you achieve a balance. This is a complex topic and I really should ask a question here sometime about it. :slight_smile:

Millard | 2020-11-07 01:20