- Home /
 
               Question by 
               Essexrookie · Feb 06, 2019 at 05:16 PM · 
                c#2dmovementrandom  
              
 
              2d obstacle moving up and down question
Hello I have multiple obstacles on a game im working on but one obstacle im having trouble with I have object moving up & down but this obstacle they all move at the same time when spawned but I would rather them move up and down differently and randomly
Movement Script
 public float freq;
 public float amp;
 Vector3 posOffset = new Vector3();
 Vector3 tempPos = new Vector3();
 void Start()
 {
     posOffset = transform.position;
 }
 void Update ()
 {
     tempPos = posOffset;
   
     transform.position = new Vector3(transform.position.x, tempPos.y + Mathf.Sin(Time.fixedTime * Mathf.PI * freq) * amp, transform.position.z);
 }
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by qobion · Feb 06, 2019 at 06:14 PM
      void Start()
      {
          freq = Random.Range(freq-1,freq+1);
          amp = Random.Range(amp-1,amp+1);
          posOffset = transform.position;
      }
 
Your answer
 
 
             Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
How to create random movement in 2D 2 Answers
Sprite is not shown moving 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                