- Home /
attract particles
Can someone translate the following piece of code into Javascript please? I realise that parts of it is already in Javascript. The only lines that my version of the Unity3D has problems with are the following:
particles[i].position = Vector3.Lerp(particles[i].position; transform.position; Time.deltaTime / 2.0f); //On Line 14
&
for (var i:int = 0; i < particles.GetUpperBound(0)){ //On Line 12
Here's all of the script together:
var p:ParticleEmitter; var particles:Particle[];
function Start() { p = (ParticleEmitter)(GameObject.Find("Magical Fire Smoke").GetComponent(typeof(ParticleEmitter))); particles = p.particles; }
function Update() { for (var i:int = 0; i < particles.GetUpperBound(0)) { particles[i].position = Vector3.Lerp(particles[i].position; transform.position; Time.deltaTime / 2.0f); } p.particles = particles; } This piece of code was taken from:
http://answers.unity3d.com/questions/61821/create-a-particle-system-that-puffs-out-particles.html
&
http://answers.unity3d.com/questions/64932/creative-way-to-attract-particles.html
Answer by Lo0NuhtiK · Dec 16, 2011 at 10:07 PM
Get rid of the semicolons inside the vector3 of this line and see if that helps ->
particles[i].position = Vector3.Lerp(particles[i].position; transform.position; Time.deltaTime / 2.0f); //On Line 14
change it to ->
particles[i].position = Vector3.Lerp(particles[i].position, transform.position, Time.deltaTime / 2.0f) ;
I've changed what you recommended and it is still co$$anonymous$$g up with two errors. Here's the updated script:
var p:ParticleEmitter;
var particles:Particle[];
function Start() {
p = (ParticleEmitter)(GameObject.Find("$$anonymous$$agical Fire Smoke").GetComponent(typeof(ParticleEmitter)));
particles = p.particles;
}
function Update() {
var i = 0;
for (i = 0; i < particles.GetUpperBound(0))
{
particles[i].position = Vector3.Lerp(particles[i].position; transform.position; Time.deltaTime / 2.0f);
}
p.particles = particles;
}
The lines that it is highlighting are:
for (i = 0; i < particles.GetUpperBound(0)) //Line 12
The error message for this is:
BCE0044: expecting ;, found ')'
The lines that it is highlighting are:
particles[i].position = Vector3.Lerp(particles[i].position; transform.position; Time.deltaTime / 2.0f);//Line 14
The error message for this is:
BCE0044: expecting :, found '='.
Answer by Lo0NuhtiK · Dec 17, 2011 at 11:32 PM
Ok, here's the whole script from the 2nd link you posted up there, converted to javascript.
#pragma strict
public var p : ParticleEmitter ;
public var particles : Particle[] ;
public var affectDistance : float ;
var sqrDist : float ;
var thisTransform : Transform ;
function Start(){
thisTransform = transform ;
p = GameObject.Find("StrangeParticles").GetComponent(ParticleEmitter) ;
particles = p.particles ;
sqrDist = affectDistance * affectDistance ;
}
function Update(){
var dist : float ;
for(var i=0 ; i < particles.GetUpperBound(0) ; i++){
dist = Vector3.SqrMagnitude(thisTransform.position - particles[i].position) ;
if(dist < sqrDist){
particles[i].position = Vector3.Lerp(particles[i].position, thisTransform.position, Time.deltaTime / 2) ;
}
}
p.particles = particles ;
}
I'm new to C# also, haven't even bothered reading any of it until the passed week of being on this site, hopefully the conversion is right and it works for you.
I still think one of the main problems is you putting semicolons inside the Vector3 ...if you notice on both of your posts about updating your script, the semicolons are still there.
Then another problem is probably the "p" variable being
p = (ParticleEmitter)(GameObject.Find("$$anonymous$$agical Fire Smoke").GetComponent(typeof(ParticleEmitter)));
when it should probably be
p = GameObject.Find("$$anonymous$$agical Fire Smoke").GetComponent(ParticleEmitter) ;
I could be wrong about that "p" variable, I'm not sure. Didn't test any of it to see.
Answer by Random Binaries · Dec 17, 2011 at 04:59 PM
I've changed what you recommended and it is still coming up with two errors. Here's the updated script:
var p:ParticleEmitter;
var particles:Particle[];
function Start() {
p = (ParticleEmitter)(GameObject.Find("Magical Fire Smoke").GetComponent(typeof(ParticleEmitter)));
particles = p.particles;
}
function Update() {
var i = 0;
for (i = 0; i < particles.GetUpperBound(0))
{
particles[i].position = Vector3.Lerp(particles[i].position; transform.position; Time.deltaTime / 2.0f);
}
p.particles = particles;
}
The lines that it is highlighting are:
for (i = 0; i < particles.GetUpperBound(0)) //Line 12
The error message for this is:
BCE0044: expecting ;, found ')'
The lines that it is highlighting are:
particles[i].position = Vector3.Lerp(particles[i].position; transform.position; Time.deltaTime / 2.0f);//Line 14
The error message for this is:
BCE0044: expecting :, found '='.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
help unity3d javascript 1 Answer
Problem with Javascript updating variables. 1 Answer
Marching Cubes for Unity in JavaScript [Concept] 1 Answer
2.5D ledge hang with javascript 0 Answers