Data Realms Fan Forums http://45.55.195.193/ |
|
Reversing Velocity http://45.55.195.193/viewtopic.php?f=73&t=15272 |
Page 1 of 2 |
Author: | Siric [ Tue Jun 09, 2009 7:51 am ] |
Post subject: | Reversing Velocity |
How would you make Pixels/MOSrotatings in a Certain radius go in the Opposite Direction they were originally going? |
Author: | Grif [ Tue Jun 09, 2009 7:53 am ] |
Post subject: | 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 |
Author: | mail2345 [ Tue Jun 09, 2009 7:55 am ] |
Post subject: | 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? |
Author: | Siric [ Tue Jun 09, 2009 7:58 am ] |
Post subject: | Re: Reversing Velocity |
Thanks Grif, I will try that. |
Author: | CrazyMLC [ Tue Jun 09, 2009 8:57 am ] |
Post subject: | 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; |
Author: | Geti [ Tue Jun 09, 2009 9:06 am ] |
Post subject: | 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. |
Author: | CrazyMLC [ Tue Jun 09, 2009 9:07 am ] |
Post subject: | Re: Reversing Velocity |
I wish I understood that. Does that basically make it stop? |
Author: | piipu [ Tue Jun 09, 2009 9:36 am ] |
Post subject: | 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. |
Author: | Siric [ Tue Jun 09, 2009 12:27 pm ] |
Post subject: | Re: Reversing Velocity |
None of the Code Snippets worked, No errors in the console, I have no idea whats wrong. |
Author: | piipu [ Tue Jun 09, 2009 1:34 pm ] |
Post subject: | 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. |
Author: | Siric [ Tue Jun 09, 2009 1:36 pm ] |
Post subject: | 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? |
Author: | CrazyMLC [ Tue Jun 09, 2009 1:38 pm ] |
Post subject: | 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. |
Author: | Siric [ Tue Jun 09, 2009 1:44 pm ] |
Post subject: | 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. |
Author: | CrazyMLC [ Tue Jun 09, 2009 1:45 pm ] |
Post subject: | 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. |
Author: | piipu [ Tue Jun 09, 2009 1:53 pm ] |
Post subject: | 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. |
Page 1 of 2 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |