ProjectileSpeed in class'Pawn'

Discussions about Coding and Scripting
User avatar
Barbie
Godlike
Posts: 2480
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

ProjectileSpeed in class'Pawn'

Post by Barbie » Fri Feb 18, 2022 11:33 am

Error correction: "class'Pawn'" was wrong, I replaced it by "class'ScriptedPawn'" --Barbie, 19. Feb 2022

This is defined in class'ScriptedPawn':

Code: Select all

var(Combat)	float	ProjectileSpeed;
It is only used in final function class'ScriptedPawn'.FireProjectile:

Code: Select all

final function FireProjectile(vector StartOffset, float Accuracy)
{
	local vector X,Y,Z, projStart;

	MakeNoise(1.0);
	GetAxes(Rotation,X,Y,Z);
	projStart = Location + StartOffset.X * CollisionRadius * X 
					+ StartOffset.Y * CollisionRadius * Y 
					+ StartOffset.Z * CollisionRadius * Z;
	spawn(RangedProjectile ,self,'',projStart,AdjustAim(ProjectileSpeed, projStart, Accuracy, bLeadTarget, bWarnTarget));
}
My expectation was that the value of ProjectileSpeed is assigned to RangedProjectile.Speed (if RangedProjectile is a Projectile), but that isn't done in any Pawn sub class as far as I have seen.
Anyway, if I implement this by setting projectile's velocity, this is not replicated to net clients :mad2:, see class'Actor':

Code: Select all

var(Movement) vector      Velocity;      // Velocity.

replication {
	unreliable if( bSimFall || ((RemoteRole==ROLE_SimulatedProxy && (bNetInitial || bSimulatedPawn)) || bIsMover) )
		Velocity;
So "ProjectileSpeed" is only useful for AdjustAim() and has to be set to the default speed value of the chosen projectile, or am I on the wrong track?

Automatically merged

I should have used the "Search" function! :facepalm:
See also topic ScriptedPawns projectiles speed and velocity from 2015.
Last edited by Barbie on Sat Feb 19, 2022 11:56 am, edited 1 time in total.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett

Buggie
Godlike
Posts: 1766
Joined: Sat Mar 21, 2020 5:32 am

Re: ProjectileSpeed in class'Pawn'

Post by Buggie » Fri Feb 18, 2022 11:51 am

Yep. It is mostly for monsters. monsters in startup can adjust ProjectileSpeed based on skill.
Later when fire very specific projectiles, they use this value:

Code: Select all

	function BeginState()
	{
		if ( ScriptedPawn(Instigator) != None )
			Speed = ScriptedPawn(Instigator).ProjectileSpeed;
If you set to monster not such fancy projectiles, then Monsters start constantly miss if you move, because prediction is wrong.

ScriptedPawn(Instigator).ProjectileSpeed used by
- GasBagBelch.uc
- KraalBolt.uc
- BruteProjectile.uc
- SkaarjProjectile.uc
So for all other need make correction of ProjectileSpeed inside ScriptedPawn.

Try use SpawnNotify for set proper Velocity before initial replication occur.
Near same as in code above.

But also not forget take in account MaxSpeed for projectile. Sometimes it capped speed, so monsters again wrong predict.

User avatar
sektor2111
Godlike
Posts: 6031
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: ProjectileSpeed in class'Pawn'

Post by sektor2111 » Fri Feb 18, 2022 6:24 pm

ProjectileSpeed inflicts some errors in client or not depending on what Monster does. It has bLeadTarget if monster is high skilled and is a "Big One" or else the majority of servers are not having anything here anyway.

Code: Select all

	if ( Skill > 2 )
		bLeadTarget = true;
	else if ( (Skill == 0) && (Health < 500) )
	{
		bLeadTarget = false;		
		ReFireRate = 0.75 * ReFireRate;
	}
Skill (real pawn skill) is linked with gameinfo's Difficulty and this can be used in Run-Line else all is ZERO. Exactly, I saw MonsterHunt servers having monster "boosted" but NO SKILL. You can check yourself what monster does with bLeadTarget, Monster without this value won't predict anything, they just fire against enemy.

Code: Select all

...
var(AI) float		Skill;			// skill, scaled by game difficulty (add difficulty to this value)
....
	if ( Level.Game != None )
		Skill += Level.Game.Difficulty; 
	Skill = FClamp(Skill, 0, 3);
	PreSetMovement();
If difficulty is Not SET, this byte is Zero heading to ZERO SKILL which will head to not "bLeadTarget" - a clumsy and dumb monster more exactly. In MH servers which I maintain this byte is ESSENTIAL, I got tired playing years against monsters firing only behind me. It's more entertaining when they attempt to predict you and you will need to change direction or you die in seconds...
Default properties for an actor which is a ServerPackage is known by client and UE1 won't replicate known values which are not changing in time. In other hand an actor will have Location more or less replicated for Projectiles - a good network it's also important, discussion is longer here and off-topic. Configuration for such a mod where access to run-line is not easy (several services are having this), you will need a new configurable variable and altering this byte. It has to be FAST because this deal it's in PreBeginPlay - usually can be used InitGame and it's what I did to my older MH mods, linking somehow that MH specific "Skill" with Level.Game.Difficulty for earning a True skill for both monsters from map and those Spawned later by Factories...

Code: Select all

event InitGame( string Options, out string Error )
{
...
...
	if (SkillMonster > 7) SkillMonster = 7;
	if (SkillMonster < 1) SkillMonster = 1;
	if ( SkillMonster == 1 )
		Difficulty = 0;
	if (SkillMonster == 2 || SkillMonster == 3)
		Difficulty = 1;
	if (SkillMonster == 4 || SkillMonster == 5)
		Difficulty = 2;
	if (SkillMonster == 6 || SkillMonster == 7)
		Difficulty = 3;
...
...
Errata: I see ProjectileSpeed a variable in class ScriptedPawn over here and NOT PAWN. It surprises me that you have it in Pawn...

User avatar
Barbie
Godlike
Posts: 2480
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: ProjectileSpeed in class'Pawn'

Post by Barbie » Sat Feb 19, 2022 11:58 am

sektor2111 wrote:
Fri Feb 18, 2022 6:24 pm
I see ProjectileSpeed a variable in class ScriptedPawn over here and NOT PAWN. It surprises me that you have it in Pawn...
Ups - a mistake, thanks for the hint. I added a comment in that post and changed "class'Pawn'" to "class'ScriptedPawn'".
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett