| Author | 
            Message | 
        
        
			| 
				
				 Siric 
				
				
					 Joined: Wed Oct 25, 2006 7:57 pm Posts: 240 Location: Out there, among the stars.
				 
				 
			 | 
			
				
				  Reversing Velocity  
					
						How would you make Pixels/MOSrotatings in a Certain radius go in the Opposite Direction they were originally going? 
					
  
			 | 
		
		
			| Tue Jun 09, 2009 7:51 am | 
			
				
					 
					
					 
				  
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 Grif 
				REAL AMERICAN HERO 
				
					 Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
				 
				 
			 | 
			
				
				  Re: Reversing Velocity  
					
						if math.abs(target.Pos.X - self.Pos.X) < 30 and math.abs(target.pos.Y - self.Pos.Y) < 30 then target.Vel = target.Vel * -1; end 
					
  
			 | 
		
		
			| Tue Jun 09, 2009 7:53 am | 
			
				
					 
					
					 
				  
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 mail2345 
				
				
					 Joined: Tue Nov 06, 2007 6:58 am Posts: 2054
				 
				 
			 | 
			
				
				  Re: Reversing Velocity  
					
						Code: for particle in MovableMan.Particles do  if math.sqrt(math.pow((particle.Pos.X-self.Pos.X),2) + math.pow((particle.Pos.Y - self.Pos.Y),2)) < <radius> then particle.Vel = Vector(particle.Vel.X * -1, particle.Vel.Y * -1) end end
  EDIT: Got ninjaed by grif. Wait, you can multiply vectors?  
					
  
			 | 
		
		
			| Tue Jun 09, 2009 7:55 am | 
			
				
					 
					
					 
				  
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 Siric 
				
				
					 Joined: Wed Oct 25, 2006 7:57 pm Posts: 240 Location: Out there, among the stars.
				 
				 
			 | 
			
				
				  Re: Reversing Velocity  
					
						Thanks Grif, I will try that. 
					
  
			 | 
		
		
			| Tue Jun 09, 2009 7:58 am | 
			
				
					 
					
					 
				  
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 CrazyMLC 
				
				
					 Joined: Fri Dec 22, 2006 4:20 am Posts: 4772 Location: Good news everyone!
				 
				 
			 | 
			
				
				  Re: Reversing Velocity  
					
						Nice shield code.
  Would want to make it f math.abs(target.Pos.X - self.Pos.X) < 30 and math.abs(target.pos.Y - self.Pos.Y) < 30 then target.Vel = target.Vel * -0.3; 
					
  
			 | 
		
		
			| Tue Jun 09, 2009 8:57 am | 
			
				
					 
					
					 
				    
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 Geti 
				
				
					 Joined: Sun Jul 13, 2008 9:57 am Posts: 4886 Location: some compy
				 
				 
			 | 
			
				
				  Re: Reversing Velocity  
					
						why is everyone using freaking Pythagoras when there is a perfectly good vector.Magnitude variable? seriously, math.abs(self.Pos.Magnitude - particle.Pos.Magnitude) works brilliantly. 
					
  
			 | 
		
		
			| Tue Jun 09, 2009 9:06 am | 
			
				
					 
					
					 
				    
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 CrazyMLC 
				
				
					 Joined: Fri Dec 22, 2006 4:20 am Posts: 4772 Location: Good news everyone!
				 
				 
			 | 
			
				
				  Re: Reversing Velocity  
					
						I wish I understood that. Does that basically make it stop? 
					
  
			 | 
		
		
			| Tue Jun 09, 2009 9:07 am | 
			
				
					 
					
					 
				    
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 piipu 
				
				
					 Joined: Mon Jun 30, 2008 9:13 pm Posts: 499 Location: Finland
				 
				 
			 | 
			
				
				  Re: Reversing Velocity  
					
						Geti wrote: why is everyone using freaking Pythagoras when there is a perfectly good vector.Magnitude variable? seriously, math.abs(self.Pos.Magnitude - particle.Pos.Magnitude) works brilliantly. I believe the reason for this is because triangles don't work that way.  Lets say we have two objects, the coordinates of which are (0,100) and (300,0). Your method gives a distance of (300 - 100) = 200. Pythagoras gives us the real distance which is sqrt((300 - 0) ^ 2 + (0 - 100) ^ 2) = 316.227766... which is not 200.  
					
  
			 | 
		
		
			| Tue Jun 09, 2009 9:36 am | 
			
				
					 
					
					 
				  
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 Siric 
				
				
					 Joined: Wed Oct 25, 2006 7:57 pm Posts: 240 Location: Out there, among the stars.
				 
				 
			 | 
			
				
				  Re: Reversing Velocity  
					
						None of the Code Snippets worked, No errors in the console, I have no idea whats wrong. 
					
  
			 | 
		
		
			| Tue Jun 09, 2009 12:27 pm | 
			
				
					 
					
					 
				  
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 piipu 
				
				
					 Joined: Mon Jun 30, 2008 9:13 pm Posts: 499 Location: Finland
				 
				 
			 | 
			
				
				  Re: Reversing Velocity  
					
						That's maybe because the radius of the effect is too small, the velocity gets reversed again the next frame, or there's something else wrong with your shield. If the script is directly attached to the shield, it will only work if the shield is not held by anyone. 
					
  
			 | 
		
		
			| Tue Jun 09, 2009 1:34 pm | 
			
				
					 
					
					 
				  
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 Siric 
				
				
					 Joined: Wed Oct 25, 2006 7:57 pm Posts: 240 Location: Out there, among the stars.
				 
				 
			 | 
			
				
				  Re: Reversing Velocity  
					
						piipu wrote: If the script is directly attached to the shield, it will only work if the shield is not held by anyone. Is it possible to make it work while held?  
					
  
			 | 
		
		
			| Tue Jun 09, 2009 1:36 pm | 
			
				
					 
					
					 
				  
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 CrazyMLC 
				
				
					 Joined: Fri Dec 22, 2006 4:20 am Posts: 4772 Location: Good news everyone!
				 
				 
			 | 
			
				
				  Re: Reversing Velocity  
					
						I don't think so, its the same deal with guns, you can't touch them when they're on an actor. 
					
  
			 | 
		
		
			| Tue Jun 09, 2009 1:38 pm | 
			
				
					 
					
					 
				    
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 Siric 
				
				
					 Joined: Wed Oct 25, 2006 7:57 pm Posts: 240 Location: Out there, among the stars.
				 
				 
			 | 
			
				
				  Re: Reversing Velocity  
					
						What if I added a Null sprited attachment and ran the script on it? I forget if you can put attachments on HeldDevices. 
					
  
			 | 
		
		
			| Tue Jun 09, 2009 1:44 pm | 
			
				
					 
					
					 
				  
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 CrazyMLC 
				
				
					 Joined: Fri Dec 22, 2006 4:20 am Posts: 4772 Location: Good news everyone!
				 
				 
			 | 
			
				
				  Re: Reversing Velocity  
					
						Nice Idea. I think that would work, if not, you could also have an emitter on it, and apply the code to the MOPixels. 
					
  
			 | 
		
		
			| Tue Jun 09, 2009 1:45 pm | 
			
				
					 
					
					 
				    
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 piipu 
				
				
					 Joined: Mon Jun 30, 2008 9:13 pm Posts: 499 Location: Finland
				 
				 
			 | 
			
				
				  Re: Reversing Velocity  
					
						The script needs to be in something that's not attached to anything. CC can't run lua from attachables at the moment. 
					
  
			 | 
		
		
			| Tue Jun 09, 2009 1:53 pm | 
			
				
					 
					
					 
				  
			 | 
    	
		
	
	
		  | 
	
	
	
		 |