Forum Discussion
RaveTZ
12 years agoProtege
HMD Roll and Particles
I'm trying to find a solution to particle effects rolling with the OVR. The issue is that camera facing particles rotate the same direction as the camera so when you tilt your head, the particles rot...
bgolus
12 years agoExplorer
You need to track the previous update's view rotation, find the rotation difference in just the roll, and apply that rotation difference to the particle.
The "perfect" rotation difference probably isn't as straightforward as grabbing the Z euler rotation of the camera on each frame update, but just the z rotation may result in decently stable results.
Then it's a matter of getting the particle list, adding this rotation difference to the existing particle rotations, and setting the particles.
Some proof of concept code:
One issue that remains with this code is Shuriken particle systems do their update from SetParticles() one frame delayed, so the particles will always swim a little bit. This also doesn't correct the initial rotation so particles with a start rotation of 0 will be aligned to your camera when emitted. You can uncomment "particleSystem.startRotation += rotationDifference * Mathf.Deg2Rad;" and it'll try to keep the particles' initial rotation aligned with the world, though if your initial particle rotation is already sufficiently randomized this isn't an issue. If you're using a small initial rotation range or rotation curve that won't work right since it'll scale the rotation values rather than properly counter rotate.
The "perfect" rotation difference probably isn't as straightforward as grabbing the Z euler rotation of the camera on each frame update, but just the z rotation may result in decently stable results.
Then it's a matter of getting the particle list, adding this rotation difference to the existing particle rotations, and setting the particles.
Some proof of concept code:
using UnityEngine;
using System.Collections;
[RequireComponent (typeof (ParticleSystem))]
public class ParticleViewRollCorrection: MonoBehaviour
{
private float lastRotation = 0f;
private ParticleSystem.Particle[] particles = new ParticleSystem.Particle[1000];
void LateUpdate()
{
if (!Camera.main)
return;
float currentRotation = Camera.main.transform.rotation.eulerAngles.z;
if (lastRotation == currentRotation)
return;
float rotationDifference = currentRotation - lastRotation;
int num = particleSystem.GetParticles(particles);
for (int i=0; i<num; i++)
particles[i].rotation += rotationDifference;
particleSystem.SetParticles(particles, num);
//particleSystem.startRotation += rotationDifference * Mathf.Deg2Rad;
lastRotation = currentRotation;
}
}
One issue that remains with this code is Shuriken particle systems do their update from SetParticles() one frame delayed, so the particles will always swim a little bit. This also doesn't correct the initial rotation so particles with a start rotation of 0 will be aligned to your camera when emitted. You can uncomment "particleSystem.startRotation += rotationDifference * Mathf.Deg2Rad;" and it'll try to keep the particles' initial rotation aligned with the world, though if your initial particle rotation is already sufficiently randomized this isn't an issue. If you're using a small initial rotation range or rotation curve that won't work right since it'll scale the rotation values rather than properly counter rotate.
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 5 years agoAnonymous
- 2 years ago
- 2 years ago