Author Topic: Fire from inside the muzzle?  (Read 1364 times)

I've been messing around with Nekram's weapon pack again. There are only two issues I've got with it so far. One, it forces the player to change their data block based on the weapon. Everyone hates that. Secondly, although the weapons raycast and have legitimate hit detection that may work in slayer, the raycast only fire from the muzzle. That means you literally cannot hurt anyone thats in your face or close enough where the weapon clips into their body. The bullet will fire behind them, making a lot of stuff awkward and annoying when things get close and personal. I noticed that the UTE raycast weapons pack does not have this issue, but it also doesn't have the best hit detection and does not adhere to friendly fire in slayer. Gravity Cat's raycasting pack has good hit detection, but it also suffers from not being able to hit things that are up close.

I've got this add-on that causes a noise and hitmarker to pop up whenever hit detection works properly, and any weapon that this doesn't work with will not work in slayer. Nekram's does and the models for the weapons are slick, so I was hoping to get some help polishing it up for a good game. There's a CS file in the pack named NewMuzzleVelocity and i'm not sure what it does exactly. I've seen it in the Warfare pack, and the bullets don't seem to move any faster than normal. I keep hearing talk of people increasing the speed of bullets but I've yet to see proof of it. Also, when I look in the cs files for the weapons, I don't see anything for raycasting. Instead, I see this:

Code: [Select]
for(%shell=0; %shell<%shellcount; %shell++)
{
%vector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%vector1 = VectorScale(%vector, %projectile.muzzleVelocity);
%vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor);
%velocity = VectorAdd(%vector1,%vector2);
%x = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%y = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%z = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z);
%velocity = MatrixMulVector(%mat, %velocity);

%p = new (%this.projectileType)()
{
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
}
return %p;
}

I have no idea what this is, but I see MuzzleVelocity, Projectile, and Vectors involved so I'm assuming this is how the bullets instantly hit stuff. If so, how do I get the bullets to fire from the back of the weapon so I can hit things that are in my face?

All this package does is allow 1) Multiple projectiles to be fired at once without additional coding for each weapon (like a shotgun) and 2) has the player's velocity affect the bullet velocity, like say, for example, if you're in a vehicle and shoot straight forward or if you're falling you won't fall past your own bullets

You can get bullets to fire from the back of the weapon by using %obj.getEyeVector() instead of %obj.getMuzzelPoint()

A raycast projectile isn't really a projectile and is just a light of sight check. Raycasting weapons use containerRayCast() to see if there's any objects between point a (the player) and point b (the maximum range of the weapon) and if the raycast finds a player in that line of sight, it damages the player and/or spawns an explosion manually, completely bypassing onProjectileHit().

From what I can gather your hitmarker add-on probably packages onProjectileHit() and as does Slayer. For compatibility it would be ideal to do a raycast and, instead of manually damaging the player or spawning an explosion, would be spawning a projectile literally inches from the player with the same properties. Most weapons don't do this as it requires a bit more coding and calculation and might cause a bit of lag on a server with a bunch of projectiles flying about and hitting stuff.

Topic belongs in modification help

All this package does is allow 1) Multiple projectiles to be fired at once without additional coding for each weapon (like a shotgun) and 2) has the player's velocity affect the bullet velocity, like say, for example, if you're in a vehicle and shoot straight forward or if you're falling you won't fall past your own bullets

You can get bullets to fire from the back of the weapon by using %obj.getEyeVector() instead of %obj.getMuzzelPoint()

A raycast projectile isn't really a projectile and is just a light of sight check. Raycasting weapons use containerRayCast() to see if there's any objects between point a (the player) and point b (the maximum range of the weapon) and if the raycast finds a player in that line of sight, it damages the player and/or spawns an explosion manually, completely bypassing onProjectileHit().

From what I can gather your hitmarker add-on probably packages onProjectileHit() and as does Slayer. For compatibility it would be ideal to do a raycast and, instead of manually damaging the player or spawning an explosion, would be spawning a projectile literally inches from the player with the same properties. Most weapons don't do this as it requires a bit more coding and calculation and might cause a bit of lag on a server with a bunch of projectiles flying about and hitting stuff.

Topic belongs in modification help

Whoops. :(

But while we're here, I wanted tell you that I switched out the bit of code you told me to. Now the bullets don't appear? To be specific, I went to where it says InitialPosition and switched it there. Gonna keep tweaking stuff, but I just wanted to let'cha know.

Whoops. :(

But while we're here, I wanted tell you that I switched out the bit of code you told me to. Now the bullets don't appear? To be specific, I went to where it says InitialPosition and switched it there. Gonna keep tweaking stuff, but I just wanted to let'cha know.
Apologizes, the correct function should be %obj.getEyePoint(); instead of %obj.getEyeVector();

Swapped that out as well, but now something weird is going on. I equip the weapon I modded and fire, but instead of the bullet coming out of the muzzle, it appears at the center of the map and fires from the ground. It initially fires down, but if I aim in the right spot, it'll fire elsewhere. This isn't just the visible projectile, but also the raycast as well. Sorry to bother you man and I appreciate the help.