How can I set an actor's SPEED to have a random value?

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
User avatar
Mini--Joe
Posts: 96
Joined: Sun Jul 27, 2014 10:25 am

How can I set an actor's SPEED to have a random value?

Post by Mini--Joe »

I have a projectile actor that when spawned, I want to have a random value between 30 and 40.

My problem is that I can't use "random(30, 40)" with the SPEED property. So how do I work around that?
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm
Contact:

Re: How can I set an actor's SPEED to have a random value?

Post by Arctangent »

Well, first off, you shouldn't expect to be able to put variable values in actor properties in the first place; Damage ( and in ZScript, DamageFuction, as the parser is stricter and doesn't allow a property to double duty like that ) is a special case.

The simplest way to do it would probably just be to set the speed to either a minimum or median value, then call [wiki]A_ScaleVelocity[/wiki] in the projectile's first state with frandom( 1.0, 1.33 ) or fradom( 0.85, 1.14 ) as the scale argument. You'll then want to make sure that the projectile never returns to that state, but that's easy enough; using Wait ( loops back to the last state endless until interrupted by an outside source ) or Goto Spawn+1 ( jumps to the state after the Spawn state, 1 can be replaced with any integer above it to increase the amount of states skipped ) in place of Loop at the end of the Spawn state sequence should be serviceable for what you're doing.
User avatar
Mini--Joe
Posts: 96
Joined: Sun Jul 27, 2014 10:25 am

Re: How can I set an actor's SPEED to have a random value?

Post by Mini--Joe »

Arctangent wrote:Well, first off, you shouldn't expect to be able to put variable values in actor properties in the first place; Damage ( and in ZScript, DamageFuction, as the parser is stricter and doesn't allow a property to double duty like that ) is a special case.

The simplest way to do it would probably just be to set the speed to either a minimum or median value, then call [wiki]A_ScaleVelocity[/wiki] in the projectile's first state with frandom( 1.0, 1.33 ) or fradom( 0.85, 1.14 ) as the scale argument. You'll then want to make sure that the projectile never returns to that state, but that's easy enough; using Wait ( loops back to the last state endless until interrupted by an outside source ) or Goto Spawn+1 ( jumps to the state after the Spawn state, 1 can be replaced with any integer above it to increase the amount of states skipped ) in place of Loop at the end of the Spawn state sequence should be serviceable for what you're doing.



This is exactly what I was looking for, thank you. I tried using A_ScaleVelocity while researching how to do this, and it seems my only mistake there was that I was ONLY using "loop".
Post Reply

Return to “Scripting”