ZScript question: Change projectile speed dynamically

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
willkuer
Posts: 267
Joined: Sat Jul 09, 2016 2:09 pm
Location: Austria

ZScript question: Change projectile speed dynamically

Post by willkuer »

I'm working on a V.A.T.S. kinda thing for my Fallout mashup mod. To work with Doom gameplay, V.A.T.S. in this case being simply a TimeFreezer powerup given to and taken from the player inventory by pressing altfire.

I use the User1 button as a hotkey to throw a frag granade from the players inventory - works fine and dandy BUT:
I'd like to have it that when CountInv says I have the TimeFreeze powerup, and I throw a grenade it slows to a crawl and the gravity on the projectile changes (changing gravity not being a problem here), and when I turn off TimeFreeze, it speeds up again to its default speed. So, I could be throwing a nade in realtime, but on it's way I switch on TimeFreeze and it should slow down and vice versa.

I'm a noob in ZScript but I have this set up so far:

Code: Select all

class FRAG : Grenade
{
	Default
	{
	Speed 20;
	Damage 1;
	DeathSound "weapons/exp1";
	BounceType "Hexen";
	BounceFactor 0.5;
	WallBounceFactor 0.3;
	BounceCount 4;
	Scale 0.75;
	Gravity 1.0;
	Decal "Scorch";
	+EXTREMEDEATH;
	+NOTIMEFREEZE;
	-GRENADETRAIL;
	+ALLOWBOUNCEONACTORS;
	+BOUNCEONACTORS;
	}
	
	States
	{
	Spawn:
	SGRN A 1
		{ if (CountInv("PowerTimeFreezerSound", AAPTR_TARGET)>0)
			{
			Gravity = Default.Gravity*0.25;
			Speed = Default.Speed*0.25;
			}
		  else
			{
			Gravity = Default.Gravity;
			Speed = Default.Speed;
			}
		}
	Loop;
	Death:
[...]
But I'm pretty sure "speed" is only taken into account when spawning. So how could I solve this?

Big thanks in advance to anybody bothering with this :)

EDIT: What I probably mean is "velocity". But I can't wrap my head around vector calculation... :(
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: ZScript question: Change projectile speed dynamically

Post by Apeirogon »

Use speed and gravity variable directly, like

Code: Select all

class bootleg : non_officially_release
{
default
{
speed 10;
gravity 1;
}
states
{
spawn:
tnt1 q 1 { self./*just to make sure that actor change itself speed*/speed *= 0.1/*means speed = speed * 0.1*/; self.gravity *= 7; /*Gravity From Jupiter*/}
}

}
Also, you still can use "decorate" A_ScaleVelocity to change projectile speed, you know!? It works in zscript too.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49073
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript question: Change projectile speed dynamically

Post by Graf Zahl »

You have to alter 'vel' which is the velocity vector. Speed is indeed only used for spawning and in a few special projectiles for later adjustments.
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: ZScript question: Change projectile speed dynamically

Post by Apeirogon »

AAAAAAAAA, my knowledge fails me(
willkuer
Posts: 267
Joined: Sat Jul 09, 2016 2:09 pm
Location: Austria

Re: ZScript question: Change projectile speed dynamically

Post by willkuer »

Thanks the two of you! Got it :)

@Graf Zahl, Danke, habs mir eh gedacht :) Gibts eigentlich wo fertige Tutorials zu ZScript Basics (für Noobs, allerdings muss ich mir Objektorientierung nicht mehr geben, das kapier ich zum Glück ;) )? Oder soll ich mir lieber gleich C reinziehen? :D
Post Reply

Return to “Scripting”