A_SpawnItemEx random velocity but not slow values - how?

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Locked
User avatar
Enjay
 
 
Posts: 27200
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

A_SpawnItemEx random velocity but not slow values - how?

Post by Enjay »

I'm guessing that there is a cunning expression that I can use for this, but I don't know what it is.

I want to use A_SpawnItemEx to spawn a projectile in any direction, but it needs to be going at least a certain speed. I want the speed to be randomised and A_CustomMissile just uses the speed in the decorate of the projectile itself. Also, I don't think that there is a DECORATE friendly way of altering a projectile's speed after it has spawned because that would have worked instead.

The problem I have is that the velocity arguments can be set up like this:

A_SpawnItemEx ("Test1", 0, 0, 0, random(-16, 16), random(-16, 16), random(-16, 16)...

That will give me any velocity value between -16 and 16 including things like -2, -1, 0, 1, 2 but I want the projectile to be going at speeds above 6 regardless of direction. So I need something like

random(-16, 16 (but not -6 to 6))

or

random(-10, 10) -6 if random value is -ve or +6 if value is 0 or +ve

Is there such an expression?

If not, perhaps I could spawn an intermediate projectile that then fires the desired one. I think that I could use A_CustomMissile to spawn the intermediate projectile and then have it spawn the actual one and have the A_SpawnItemEx velocities added to those of the intermediate projectile. Right?
Gez
 
 
Posts: 17946
Joined: Fri Jul 06, 2007 3:22 pm

Re: A_SpawnItemEx random velocity but not slow values - how?

Post by Gez »

There are several ways to do that. Here is a simple one:

Code: Select all

random(7, 16)*((random(0, 1)*2)-1)
random(0, 1)*2 will give either 0*2 = 0 or 1*2 = 2. Subtract 1, and you get either +1 or -1. So you'll get a random number between 7 and 16 which will randomly be positive or negative.
User avatar
Enjay
 
 
Posts: 27200
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: A_SpawnItemEx random velocity but not slow values - how?

Post by Enjay »

Excellent. Thank you very much. I hadn't even considered just using a +ve random number multiplied by a randomised +ve/-ve.
User avatar
amv2k9
Posts: 2178
Joined: Sun Jan 10, 2010 4:05 pm
Location: Southern California

Re: A_SpawnItemEx random velocity but not slow values - how?

Post by amv2k9 »

Enjay wrote:...Also, I don't think that there is a DECORATE friendly way of altering a projectile's speed after it has spawned because that would have worked instead.
[wiki]A_ScaleVelocity[/wiki]? Unless you want one actor to alter the speed of another projectile. Then you'd have to get into ACS, I suppose.
User avatar
Enjay
 
 
Posts: 27200
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: A_SpawnItemEx random velocity but not slow values - how?

Post by Enjay »

Ah yes, I possibly could have worked something out with that if I'd remembered it existed (I was even searching for something like it but my Wiki-fu failed). However, Gez's solution is nice and simple and does exactly what I want. Thanks for reminding me about A_ScaleVelocity though.
Locked

Return to “Editing (Archive)”