Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Random Binaries · Dec 16, 2011 at 09:00 PM · javascriptparticlesparticle

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
2

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) ;

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Random Binaries · Dec 17, 2011 at 08:39 PM 0
Share

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 '='.

avatar image
1

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lo0NuhtiK · Dec 17, 2011 at 11:39 PM 0
Share

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.

avatar image
0

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 '='.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges