I want to destroy particles by another particles in unity - unityscript

I am making a game like fire fighter and I had made a fire by particles system , and using fire extinguisher just a prefab, which emitting another particles and iI want when 2nd particles collides with first particles (fire) then first particles (fire) will destroy?
Any Suggestions? Thanks in Advance.. :-)
I had already tried about particle colliding and some others
like
collision col;
if(gameObject.name=="Particle")
Destroy(col.gameObject);

If you attach this script to Water particle, and you have a Fire particle, then in your water collision script
if (other.gameObject.name=="Fire")
{
Destroy(other.gameObject);
// bonus effect for smoke particles
// Instantiate(smokeObject, other.gameObject.transform.position, other.gameObject.transform.rotation);
}

Related

Cannon.js - How to prevent objects clipping 'floor' on update

I'm using Cannon.js with Three.js.
I've created a scene which consists of 1 heightfield and 5 balls. I want the balls to roll around the heightfield, using the cannon.js physics.
On mouse move, I rotate the heightfield along the y-axis to make the spheres roll back and forth.
I have an update loop, which copies the sphere position & quaternion from cannon.js and applies to the visual sphere of three.js.
The heightfield is also updated at the same time as the three.js visual floor. Both of these run in a for loop, in requestAnimationFrame.
updateMeshPositions() {
for (var i = 0; i !== this.meshes.length; i++) {
this.meshes[i].position.copy(this.bodies[i].position);
this.meshes[i].quaternion.copy(this.bodies[i].quaternion);
this.hfBody.position.copy(this.mesh.position);
this.hfBody.quaternion.copy(this.mesh.quaternion);
}
}
However, the problem is that when the 'floor' is rotating back and forth, the spheres are getting stuck and sometimes even falling through the floor. Here is an example on codepen - https://codepen.io/danlong/pen/qJwMBo
Move the mouse up and down on the screen to see this in action.
Is there a better or different way I should be rotating the 'floor' whilst keeping the sphere's moving?
Directly (i.e. "instantly") setting position/rotation is likely to break collision handling in all physics engines, including cannon.js . Effectively you are teleporting things through space, causing objects to get stuck in or pass through each other.
What you should do is
Set the velocity (both .velocity and .angularVelocity) or apply forces to the Cannon.js bodies
Copy the transform of those bodies to your visual meshes (notices this is exactly the other way around of what you are currently doing in the code)
Determining the right amount of force to apply to get the desired visual behavior is usually the tricky part.

To control 3D type Snake Game's movement when turning by WebGL

I hope to create a 3D type Snake game by Babylon or THREE.js.
Here's the picture about how i want the snake to move when the snake to turn left or turn right.
movement comparison
That is, I want the snake to move more "smoothly", just like the car's movement when it turn left or turn right.
Do I need skeleton animation to achieve this goal? If so, could you give me a solution/suggestion about how to implement it.
Another potential (likely simpler) way to do it would be to use a particle system. When snake grows you could just change the params on the particle system, then the engine would be responsible for handling smoothing.
Particle system would just need to adhere to the following rules:
Particles shoot out in one direction from the head mesh.
Particles minimum_lifetime = maximum_lifetime
Particle minimum_speed = maximum_speed
Then as it grows in size you just increment the particles direction. And you then just compare head position to it's particle (tail) positions to check for collisions.
The default particle system in BJS doesn't as far as I know support collisions officially, but you could query the positions of the particles to check for collisions, or use the solid particle system which allows for physics. (SPS is probably the best way to go in the end).
Here is an example playground however just to demonstrate the movement.
https://playground.babylonjs.com/#PLRKFW#1

Disable Particle rotation in Three.js

I'm trying to use Three.js to create an ’asteroid field' using particle systems or point clouds or stuff like that. One of the problems I've bumped into with all of these is that when the camera rotates around the z axis, the particles rotate individually with the camera, preserving the same orientation no matter how the camera is turned. I want the simulation to look as if the user is flying through a bunch of asteroids, and obviously asteroids don't magically spin whenever you tilt your head, so I was wondering if there is any way to prevent them from turning when the camera turns. Must particles always be upright?
If you want to rotate sprites you can use attribute SpriteMaterial.rotation:
var sprite = new THREE.Sprite( new THREE.SpriteMaterial({map: texture,rotation: Math.PI/4}));
see this http://threejs.org/examples/webgl_sprites.html
In your case, rotation of all sprites should be equal to camera rotation.

Physijs jittering mesh and wrong rotation?

I am making a game in three.js and I have 2 questions. 1. I have a cube which gets pushed along but every few seconds it "Jitters" back a little. Why?. 2. When i click the left or right arrow key the cube meant to rotate on its Y-axis instead of rotating one way it sometimes rotates a little one way and then the other?.
So I realised that I was updating the camera in the Renderer update function not the physics update function so I moved it and now there is no jittering. Also for the rotation I changed .rotation.y -= 0.1; to .rotateOnAxis( new THREE.Vector3(0,1,0), -0.05); and now it works.

libGDX: How to let the camera point to moving sprite?

I'm new to libGDX and android game dev. And I want to achieve this:
I have a Screen and within it, a ball sprite that is moving along the X axis. Now I want to center the viewport to the sprite when it moves. Just like in Angry birds, where the camera follows the bird flying across the sky.
How can I implement that within my game using OrthographicCamera?
This took me a while of Googling and testing, but I just found something and I think others may appreciate it.
To move the camera (and if you are using a spriteBatch), make sure to call setProjectionMatrix.
Ex:
camera.position.y += 5; // or whatever you want to change y by...
camera.position.x += 5;
camera.update();
spriteBatch.setProjectionMatrix(camera.combined);
Hope this helps someone!
In case you haven't figured this out yet, you need to convert the ball position to the camera position using
camera.unproject(ballPosition)
This converts the screen coordinates into world coordinates. Then call
camera.position(ballPosition)
to set the camera position to your ball's location in the world.
The
camera.translate(...);
function translates all of the involved attributes the camera by the given data. After the operation you need to call
camera.update();
to calculate the new matrices of the camera. This will push the camera to the direction you want.

Resources