View unanswered posts | View active topics It is currently Fri Jan 10, 2025 7:25 pm



Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
 Reversing Velocity 
Author Message
User avatar

Joined: Wed Oct 25, 2006 7:57 pm
Posts: 240
Location: Out there, among the stars.
Reply with quote
Post 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
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post 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
Profile
User avatar

Joined: Wed Oct 25, 2006 7:57 pm
Posts: 240
Location: Out there, among the stars.
Reply with quote
Post Re: Reversing Velocity
Thanks Grif, I will try that.


Tue Jun 09, 2009 7:58 am
Profile
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post Re: Reversing Velocity
I wish I understood that.
Does that basically make it stop?


Tue Jun 09, 2009 9:07 am
Profile WWW
User avatar

Joined: Mon Jun 30, 2008 9:13 pm
Posts: 499
Location: Finland
Reply with quote
Post 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.
Image
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
Profile
User avatar

Joined: Wed Oct 25, 2006 7:57 pm
Posts: 240
Location: Out there, among the stars.
Reply with quote
Post 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
Profile
User avatar

Joined: Mon Jun 30, 2008 9:13 pm
Posts: 499
Location: Finland
Reply with quote
Post 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
Profile
User avatar

Joined: Wed Oct 25, 2006 7:57 pm
Posts: 240
Location: Out there, among the stars.
Reply with quote
Post 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
Profile
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Wed Oct 25, 2006 7:57 pm
Posts: 240
Location: Out there, among the stars.
Reply with quote
Post 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
Profile
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Mon Jun 30, 2008 9:13 pm
Posts: 499
Location: Finland
Reply with quote
Post 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
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 19 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.080s | 14 Queries | GZIP : Off ]