The Projectile Weapon Conundrum!

preview_player
Показать описание


I've been working on a Projectile weapon for my FPS template and I've been dealing with a very interesting problem this week. I'm not sure it's worth leaving in so I'm leaving it up to you to tell me.

When designing a projectile weapon you're often required to make a descision about where the project weapon goes if it's not going to collide with something. In Godot you can use Project Ray on the camera to return a position in the distance that you can use to place a pseudo target in the distance for a projectile to travel to.

Please like and Subscribe! It's truly appreciated

#GameDevelopment #GameDesign #Godot

Links to my Socials

Рекомендации по теме
Комментарии
Автор

I think it’s one of those things so minor that it doesn’t matter, the simpler the better imo because if you start going down every tiny rabbit hole you’ll never finish a project
When I make projects I have very clear simple goals and the moment I accomplish them i not and problems I had then move on to the next project

DaSpineLessFish
Автор

Your implementation of using a raycast that only goes for 600 units to determine trajectory was my first thought as well. But it actually highlights an issue with using raycasts to set trajectory for projectile weapons at all. So you mention that the issue with your 600-unit-raycast implementation is that eventually the rocket will cross over the center point and seem to be veering off course, but it won't actually matter because players can't see it unless they really crank their draw distance.

My thought here is that, this problem of crossing over the center of the screen and veering off course would get worse the closer you terminate that raycast. Like, if you only shot the raycast out 100 units instead of 600. Now, when firing into the air that's not a problem, because you know it'll always be 600 units.

But picture this:
You're aiming your rocket down a long corridor and are about to press fire to blow up a door at the end of the long corridor. Just as you're about to fire an enemy runs across your field of view and is only 100 units away. You pull the trigger, the raycast detects that enemy and uses its position to set the trajectory for your rocket. But the enemy keeps moving and by the time the projectile leaves your weapon, the enemy is no longer in front of you to get hit.

Now you have that same issue where the rocket will cross over the center of the screen and appear veer off course. But it will be much more pronounced because the crossover point is only 100 units away. It may even end up hitting the left wall of the corridor instead of making it all the way to the end of the corridor and hitting the door which was the intended target, and what the rocket should be hitting.

All of that said, I think there are two options here depending on the context of your game:

1. Just do forward firing like you were initially (But for everything. Just don't use raycasts at all for projectile trajectory) and add some sort of shake or recoil to the weapon. The recoil would move your reticle and the fact that the projectile doesn't line up perfectly won't be as noticeable; However, this only works for explosive weapons at short distances.

If you were firing a rocket at a small point a mile away and the player watched the explosion, they would see that the rocket didn't actually hit exactly where they pointed their cursor.
Like, imagine if the player was shooting at a sign that said "HOTEL" and they aimed at the center of the 'O'. from that distance, since the rocket fires off to the right a bit, the player would likely actually hit the T or the E. With explosive weapons the explosion might mask this effect at closer distances, it will become noticeable further out.

If you plan on adding any sort of precision projectile weapons, Like a bow & arrow or throwing knives, you'll have the same issue at much closer distances. If the player throws a knife at a nearby wall, then walks up to it, they'll be able to see that their knives are firing off to the right a little bit.

2. Do something to line them up properly. DartVonGrell in the comments had a good solution.

Christopher-menf
Автор

I prefer camera alignment. I think it makes more sense for players. Projectiles should go where you're aiming, not where the weapon is.

AJMarraffa
Автор

The problem with hitscan rockets is: What if you miss a player with the hitscan, but they walk right into the missile's explosion?

JilutheFang
Автор

I must be in real danger because I have not been paying attention to details that small in games I have made.

thomaseubank
Автор

I've spent just less than a week on my first godot project and i've noticed this right away, missing shots from close by. I have tried my best to implement the other solution where I have a raycast on the camera which extends 500 on the z axis. And i conditionally try to correct the trajectory of the bullet (that is spawned at the end of the gun). If there is a collision point, then my goal is to set the direction to it, else ill set it to the end of this raycast. However all those are so confusing to me - that the only thing i achieved is creating a scuffed aimbot :D Still struggling to solve this the way i intended and this is the only other source i found where people mention this problem apart from a reddit post which has no code example, just a mention of this.

eyyMinda
Автор

Hey man im no game designer or any but....

How about you change the trajectory after the rocket fires..

Like first it emerges from the rocket toward the reticle (heading where ever)

Then it lerps trajectory toward the final destination (the one with 100% acuracy)

shirotonbo
Автор

i use both methods with raycast. When it's colliding it get collision point while not it took viewport / 2

Boildroid