Jump to content
  • 0

A_SpawnParticleEx() math question


Rifleman

Question

Hi everyone,

 

I've been playing around with particles to make actors more visually appealing and I need an advice - tried searching but couldn't find anything relevant or simple enough to copy. Can someone please help me fill in the blanks?

 

Lets say I have an actor with 40 height and 20 radius, a sphere. I'd like to be able to spawn particles randomly all along its surface, going straight up(relatively, not absolutely), if put in a loop like override void Tick().

 

Sounds simple, but I can't crack this one; something is always wrong no matter what I try - this kind of math wasn't my favourite in high school. :D 

 

Thanks for any info or examples!

 

Spoiler

Class BlueSphere : Actor
{
    override void Tick()
    {
        super.Tick();

 

       


        A_SpawnParticleEx
        (
            "0000FF",
            TexMan.CheckForTexture (""),
            style: STYLE_Add,
            flags: SPF_FULLBRIGHT|SPF_RELATIVE,
            lifetime: 15,
            size: 2.0,
            angle: ?,
            xoff: ?,
            yoff: ?,
            zoff: ?,

            velx: ?,

            vely: ?,
            velz: ?,
            accelx: ?,

            accely: ?,
            accelz: ?,
            startalphaf: 1.0,
            fadestepf: -0.2,
            sizestep: 0,
        );
    }
}

 

RS.gif.4e7950a3a15760b618d19e5b2eef6fd8.gif Pic is just for flavour.

Share this post


Link to post

1 answer to this question

Recommended Posts

  • 1

I understand it that you want particles to shoot from surface of a sphere, in direction perpendicular to the surface.

 

I had similar thing and solved it like this:

 

Generate random numbers for angle and pitch:

double a = frandom(0, 360);
double p = (frandom(-90, 90) + frandom(-90, 90)) * 0.5;

 

Then the particle parameters shall be:

angle: a,

xoff: cos(a) * cos(p) * R,
yoff: sin(a) * cos(p) * R,
zoff: sin(p) * R + H,

velx: cos(a) * cos(p) * S,
vely: sin(a) * cos(p) * S,
velz: sin(p) * S,

where a and p are previously generated numbers, R is sphere radius, H is z distance from thing origin position to sphere center, and S is desired particle speed.

I don't know what acceleration you want, but it shouldbe similar to the vel parameters (or just 0 if you don't want any acceleration).

 

I hope I did not make any typo or mistake here.

 

Edit: This solution relies on NOT having the SPF_RELATIVE flag used.

Edit 2: I do not recommend creating particles (or doing anything at all) from Tick() method on inventory items... It can have undesirable effects when they are in someone's inventory, or when inactive and invisible waiting for respawn. The particle creation should be better handled in some function called from the actor's states.

Edited by jaeden

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...