Projectile collision issues. (Custom Weapon)

Discussions about Coding and Scripting
Post Reply
User avatar
SilverSound
Adept
Posts: 341
Joined: Fri Nov 06, 2015 10:12 am
Personal rank: Curious
Location: St. Cloud, Florida

Projectile collision issues. (Custom Weapon)

Post by SilverSound »

Yesterday I rediscovered some weapons I made a while back. Getting to the point one of the weapons Has a problem.

I modified the flack cannon to shoot custom shock projectiles that fly fast. But the problem comes in when I shoot. They all collide and cause me to die.

My solution would be to stop them from colliding....but I don't know how to do this.

Does anyone know how I could achieve this? I would really love to know how to get this working.


Here is a video showing the problem:(first weapon is the flack. the rest are a showcase of other things I did for fun.)
zAoZ14vJq90


Edit:I tried to upload the script but couldn't. so here is the fire code instead.

Code: Select all

// Fire chunks
function Fire( float Value )
{
	local Vector Start, X,Y,Z;
	local Bot B;
	local Pawn P;

	if ( AmmoType == None )
	{
		// ammocheck
		GiveAmmo(Pawn(Owner));
	}
	if (AmmoType.UseAmmo(1))
	{
		bCanClientFire = true;
		bPointing=True;
		Start = Owner.Location + CalcDrawOffset();
		B = Bot(Owner);
		P = Pawn(Owner);
		P.PlayRecoil(FiringSpeed);
		Owner.MakeNoise(2.0 * P.SoundDampening);
		AdjustedAim = P.AdjustAim(AltProjectileSpeed, Start, AimError, True, bWarnTarget);
		GetAxes(AdjustedAim,X,Y,Z);
		Spawn(class'WeaponLight',,'',Start+X*20,rot(0,0,0));		
		Start = Start + FireOffset.X * X + FireOffset.Y * Y + FireOffset.Z * Z;	
		Spawn( class 'SuperShock',, '', Start, AdjustedAim);
		// lower skill bots fire less flak chunks
		if ( (B == None) || !B.bNovice || ((B.Enemy != None) && (B.Enemy.Weapon != None) && B.Enemy.Weapon.bMeleeWeapon) )
		{
			Spawn( class 'ShockProj',, '', Start + Y - Z, AdjustedAim);
			Spawn( class 'SuperShock',, '', Start + 4 * Y + Z, AdjustedAim);
		}
		else if ( B.Skill > 1 )
			Spawn( class 'MyPlasmaSphere',, '', Start + Y - Z, AdjustedAim);

		ClientFire(Value);
		GoToState('NormalFire');
	}
}
"Woah what?! I wish I was recording that...."
User avatar
FXANBSS
Skilled
Posts: 231
Joined: Thu Dec 26, 2013 7:03 pm

Re: Projectile collision issues. (Custom Weapon)

Post by FXANBSS »

The Shock projectiles have a small collision box, put the CollisionHeight and CollisionRadius to 0.
But you can't do a shock combo sadly.
UTX
Skilled
Posts: 214
Joined: Fri Aug 28, 2015 3:39 am

Re: Projectile collision issues. (Custom Weapon)

Post by UTX »

All you gotta do is change the process touch function so the projectiles don't interact with each other.
User avatar
SilverSound
Adept
Posts: 341
Joined: Fri Nov 06, 2015 10:12 am
Personal rank: Curious
Location: St. Cloud, Florida

Re: Projectile collision issues. (Custom Weapon)

Post by SilverSound »

UTX wrote:All you gotta do is change the process touch function so the projectiles don't interact with each other.
FXANBSS wrote:The Shock projectiles have a small collision box, put the CollisionHeight and CollisionRadius to 0.
But you can't do a shock combo sadly.
Alright. I'll do a quick look and see if I can get that line of code in my child class so I can change it. It most likely will work but It's good to never assume with coding...

Don't need shock combos with this gun. That would be kinda bad anyway. Might want to change the color of the projectile later to make it so others know not to try it.

Thanks for your replies! I'll edit with report shortly.


Edit:haha trying the CH CR = 0 thing makes them not collide with Pawns. going to have to try to mod the touch function
Last edited by SilverSound on Wed Feb 24, 2016 1:34 am, edited 1 time in total.
"Woah what?! I wish I was recording that...."
UTX
Skilled
Posts: 214
Joined: Fri Aug 28, 2015 3:39 am

Re: Projectile collision issues. (Custom Weapon)

Post by UTX »

ProcessTouch has to be modified in the projectile, not in the weapon.
User avatar
SilverSound
Adept
Posts: 341
Joined: Fri Nov 06, 2015 10:12 am
Personal rank: Curious
Location: St. Cloud, Florida

Re: Projectile collision issues. (Custom Weapon)

Post by SilverSound »

ok I see the code for this.

Code: Select all

auto state Flying
{
	function ProcessTouch (Actor Other, vector HitLocation)
	{
		If ( (Other!=Instigator) && (!Other.IsA('Projectile') || (Other.CollisionRadius > 0)) )
			Explode(HitLocation,Normal(HitLocation-Other.Location));
	}

	function BeginState()
	{
		Velocity = vector(Rotation) * speed;	
	}
}
I deleted the line for " (!Other.IsA('Projectile') || (Other.CollisionRadius > 0))" but it still seems to collide with it'self. What am I doing wrong here?
"Woah what?! I wish I was recording that...."
UTX
Skilled
Posts: 214
Joined: Fri Aug 28, 2015 3:39 am

Re: Projectile collision issues. (Custom Weapon)

Post by UTX »

Because you made it so it will collide with projectiles.

This should work better, remember to replace "QWERY" with the projectile class you're making.

Code: Select all

auto state Flying
{
   function ProcessTouch (Actor Other, vector HitLocation)
   {
      If ( (Other!=Instigator) && (!Other.IsA('Projectile') || (Other.CollisionRadius > 0)) && !Other.IsA ('QWETY'))
         Explode(HitLocation,Normal(HitLocation-Other.Location));
   }

   function BeginState()
   {
      Velocity = vector(Rotation) * speed;   
   }
}
Or

Code: Select all

auto state Flying
{
   function ProcessTouch (Actor Other, vector HitLocation)
   {
      If ( (Other!=Instigator) && (!Other.IsA('Projectile') || (Other.CollisionRadius > 0)) && Other.Class != Class 'QWERTY')
         Explode(HitLocation,Normal(HitLocation-Other.Location));
   }

   function BeginState()
   {
      Velocity = vector(Rotation) * speed;   
   }
}
User avatar
SilverSound
Adept
Posts: 341
Joined: Fri Nov 06, 2015 10:12 am
Personal rank: Curious
Location: St. Cloud, Florida

Re: Projectile collision issues. (Custom Weapon)

Post by SilverSound »

UTX wrote:Because you made it so it will collide with projectiles.

This should work better, remember to replace "QWERY" with the projectile class you're making.
Oh! I see. Thank you for clarifying this. It didn't seem that obvious. Sometimes the scripts for UT can be a bit complicated to the point it's confusing. I miss took what it said.


Edit:It seems they don't collide anymore but they still explode.((Edit3: I don't even know if they aren't colliding...I'm not sure what's making them explode. The code should make it impossible to hit the instigator.)) Meaning it's hitting me (the gun user) Unless it's something else? Also I can't seem to get my projectiles to spread like the UT_Chunk's. The random direction code is there so I'm not sure if it's placement or just something I'm doing wrong.(I think I might know what's up...I pointed it out in the code. Tell me if I'm wrong)

Edit2:I'm wrong....

Code: Select all

//=============================================================================
// SuperShock4.
//=============================================================================
class SuperShock4 expands ShockProj;

var int NumWallHits;
var bool bCanHitInstigator, bHitWater;


	simulated function PostBeginPlay()
	{
		local rotator RandRot;

		if ( Level.NetMode != NM_DedicatedServer )
		{
			if ( !Region.Zone.bWaterZone )
			SetTimer(0.1, true);
		}

		if ( Role == ROLE_Authority )
		{
			RandRot = Rotation;
			RandRot.Pitch += FRand() * 2000 - 1000;
			RandRot.Yaw += FRand() * 2000 - 1000;
			RandRot.Roll += FRand() * 2000 - 1000;
			Velocity = Vector(RandRot) * (Speed + (FRand() * 200 - 100));
			if (Region.zone.bWaterZone)
				Velocity *= 0.65;
		}
		Super.PostBeginPlay();
	}

/////////////////////////////////////////////////////
auto state flying

{
simulated function HitWall (vector HitNormal, actor Wall)
	{
		local vector Vel2D, Norm2D;

		bCanHitInstigator = true;
		PlaySound(ImpactSound, SLOT_Misc, 2.0);
		LoopAnim('Spin',1.0);
		if ( (Mover(Wall) != None) && Mover(Wall).bDamageTriggered )
		{
			if ( Role == ROLE_Authority )
				Wall.TakeDamage( Damage, instigator, Location, MomentumTransfer * Normal(Velocity), MyDamageType);
			Destroy();
			return;
			}

				NumWallHits++;
				SetTimer(0, False);
				MakeNoise(0.3);
				if ( NumWallHits > 15 )
					Destroy();

		if ( NumWallHits == 1 ) 
		{
			Spawn(class'WallCrack',,,Location, rotator(HitNormal));
			Vel2D = Velocity;
			Vel2D.Z = 0;
			Norm2D = HitNormal;
			Norm2D.Z = 0;
			Norm2D = Normal(Norm2D);
			Vel2D = Normal(Vel2D);
			if ( (Vel2D Dot Norm2D) < -0.999 )
			{
				HitNormal = Normal(HitNormal + 0.6 * Vel2D);
				Norm2D = HitNormal;
				Norm2D.Z = 0;
				Norm2D = Normal(Norm2D);
				if ( (Vel2D Dot Norm2D) < -0.999 )
				{
					if ( Rand(1) == 0 )
						HitNormal = HitNormal + vect(0.05,0,0);
					else
						HitNormal = HitNormal - vect(0.05,0,0);
					if ( Rand(1) == 0 )
						HitNormal = HitNormal + vect(0,0.05,0);
					else
						HitNormal = HitNormal - vect(0,0.05,0);
					HitNormal = Normal(HitNormal);
				}
			}
		}
		Velocity -= 2 * (Velocity dot HitNormal) * HitNormal;  
		
	}


	function SetUp()    //<<<This is causeing the random rotation to not work. ? will test anyway. Thought I'd post before I recompile for the 80th time...this is fun
	{
		local vector X;

		X = vector(Rotation);	
		Velocity = Speed * X;     // Impart ONLY forward vel
		if (Instigator.HeadRegion.Zone.bWaterZone)
			bHitWater = True;	
	}

        function ProcessTouch (Actor Other, vector HitLocation)
        {
                 If ( (Other!=Instigator) && (!Other.IsA('Projectile') || (Other.CollisionRadius > 0)) && Other.Class != Class 'SuperShock4')
         Explode(HitLocation,Normal(HitLocation-Other.Location));;
        }


	function BeginState()
	{
		Velocity = vector(Rotation) * speed;	
	}

}

defaultproperties
{

     speed=2800.000000
     MaxSpeed=200000.000000
     bBounce=True
}


EDIT70:ok. I'm an idiot. I placed the "chunks" in the wrong part of the flack code. :loool: They do not collide or explode anymore. Now I need to figure how how to get them to spread like the flack chunks themselves.

I'll continue to investigate. But if someone knows the answer please let me know. (I would like to avoid making a whole new topic for something as small as this when It's sorta related to my custom weapon in this thread. Let me know if I'm wrong there.) Thanks all!

Edit5: So I did a little snooping on the codes and I noticed something the chunks don't have that the shockproj does. An auto state "flying"

This leads me to believe that this state is what's keeping the projectiles from actually flying in a scatter pattern until they are in physics falling. I'll quickly check to make sure this is the case. (Looks as though it was indeed the reason! Nice. A fun experience.
"Woah what?! I wish I was recording that...."
UTX
Skilled
Posts: 214
Joined: Fri Aug 28, 2015 3:39 am

Re: Projectile collision issues. (Custom Weapon)

Post by UTX »

With projectiles like the shockproj that travel in a straight line, you need to change the rotation in which they spawn, but slightly or they can even spawn behind the player.
User avatar
SilverSound
Adept
Posts: 341
Joined: Fri Nov 06, 2015 10:12 am
Personal rank: Curious
Location: St. Cloud, Florida

Re: Projectile collision issues. (Custom Weapon)

Post by SilverSound »

UTX wrote:With projectiles like the shockproj that travel in a straight line, you need to change the rotation in which they spawn, but slightly or they can even spawn behind the player.
Yes. But with the shockproj specifically it has a line of code that forces it to go in a set direction relative to where you are pointing.

Getting rid of that let the random spread line of code from the UTchunks do it's magic.

I got it all working. The shockproj has a Bool that makes them target-able by projectiles. It overrides the process touch line you added. Had to set it to false to fix it.
A fun experience in deed.
"Woah what?! I wish I was recording that...."
Post Reply