Skip to content

Commit

Permalink
Fix attached particle spawners far from spawn (#6479)
Browse files Browse the repository at this point in the history
* Fix attached particle spawners far from spawn

When far from spawn, attached particle spawners
did not spawn particles.
  • Loading branch information
raymoo authored and nerzhul committed Sep 30, 2017
1 parent be10c08 commit 8c16f18
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/particles.cpp
Expand Up @@ -317,14 +317,18 @@ void ParticleSpawner::step(float dtime, ClientEnvironment* env)
v3f ppos = m_player->getPosition() / BS;
v3f pos = random_v3f(m_minpos, m_maxpos);

// Need to apply this first or the following check
// will be wrong for attached spawners
if (is_attached)
pos += attached_pos;

if (pos.getDistanceFrom(ppos) <= radius) {
v3f vel = random_v3f(m_minvel, m_maxvel);
v3f acc = random_v3f(m_minacc, m_maxacc);

if (is_attached) {
// Apply attachment yaw and position
pos.rotateXZBy(attached_yaw);
pos += attached_pos;
vel.rotateXZBy(attached_yaw);
acc.rotateXZBy(attached_yaw);
}
Expand Down Expand Up @@ -377,14 +381,18 @@ void ParticleSpawner::step(float dtime, ClientEnvironment* env)
v3f ppos = m_player->getPosition() / BS;
v3f pos = random_v3f(m_minpos, m_maxpos);

// Need to apply this first or the following check
// will be wrong for attached spawners
if (is_attached)
pos += attached_pos;

if (pos.getDistanceFrom(ppos) <= radius) {
v3f vel = random_v3f(m_minvel, m_maxvel);
v3f acc = random_v3f(m_minacc, m_maxacc);

if (is_attached) {
// Apply attachment yaw and position
pos.rotateXZBy(attached_yaw);
pos += attached_pos;
vel.rotateXZBy(attached_yaw);
acc.rotateXZBy(attached_yaw);
}
Expand Down

4 comments on commit 8c16f18

@orwell96
Copy link
Contributor

@orwell96 orwell96 commented on 8c16f18 Sep 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to move the pos.rotateXZBy() instruction, or the resulting position will be wrong when the object has a yaw !=0
(The rotation has to be done BEFORE the attached position is applied!

@raymoo
Copy link
Contributor Author

@raymoo raymoo commented on 8c16f18 Sep 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orwell96 Thanks for catching.

@orwell96
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I committed this change... nevermind

@orwell96
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b9fb3ce.

Please sign in to comment.