Magnet repulsion

Get help using Construct 2

Post » Sat Mar 09, 2013 6:23 pm

Hi. I've follow an example in forum for create a repulsion magnet.
Now I've the player that change gravity force in positive or negative. When the gravity is positive, magnet work fine, but with negative gravity, magnet attracts the player.
Here the image of the events, maybe someone can help me.



[edit]:
Cap file
https://jumpshare.com/v/lqe0MAZdphluQijRq5Ug?b=DhxIAPibkqXQUeG5vGlUgamegamegame2013-03-10 02:29:40
B
17
S
5
G
3
Posts: 76
Reputation: 2,948

Post » Sat Mar 09, 2013 9:01 pm

It looks like an error with the variable 'forza', although maybe there's more code above this that we can't see. But as this code stands, it looks as though it will toggle the variable every frame. One frame does -forza, then the next frame it does -forza again so it'd keep toggling?

The way I'd do it, I'd move the object towards/away from the magnet, just using the angle between the two, and just set up a seperate line of code for each situation. So....

Animation Frame = 0
Move Object at angle(x,y,x,y) + distance
Animation Frame =1
Move object at angle(x,y,x,y) - distance

That might be a bit too simple for your needs though, it looks like you're trying to do it a bit more precisely.
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Sat Mar 09, 2013 10:13 pm

perhaps it is as simple as

if gravityReversed > fx *= -1, fy *= -1 right before you add the fx and fy to the vectors at the end?
B
6
S
1
G
1
Posts: 70
Reputation: 702

Post » Sat Mar 09, 2013 10:58 pm

@farflames: Don't work

@cincipon: I don't understand, sorry i'm not english, you can explain it better?
B
17
S
5
G
3
Posts: 76
Reputation: 2,948

Post » Sun Mar 10, 2013 2:01 am

I'm suggesting that since it works fine when gravity is normal, having a condition that checks to see if gravity is reversed will let you then add an action that reverses the force of the magnets. The best place I see to do this is right before you "Set Platform VectorX" and "Set Platform VectorY".

Something like :

On Condition "GRAVITY IS REVERSED"
Action "fx = fx * -1" Action "fy = fy * -1"
B
6
S
1
G
1
Posts: 70
Reputation: 702

Post » Sun Mar 10, 2013 2:29 am

Don't work. Here my capx file, so you can look it!

https://jumpshare.com/v/lqe0MAZdphluQijRq5Ug?b=DhxIAPibkqXQUeG5vGlU
B
17
S
5
G
3
Posts: 76
Reputation: 2,948

Post » Sun Mar 10, 2013 3:44 am

Hmm. I see that your problem is more complicated than I thought from your description.

If you want the magnet to repulse, perhaps it would be best tomake an invisible sprite around it, and when the player collides with the trigger sprite you could send it a physics impulse based on the angle between the player and the magnet?

As it stands now, your code has too much going on aside from the problem at hand for me to jump into.

Good luck!
B
6
S
1
G
1
Posts: 70
Reputation: 702

Post » Tue Jun 18, 2013 12:07 am

Hi,

Ive the same proble... i follow the another post... no have a another "easy solution" for magnet/repulsion objet?

Note: Would be great in future a beahvior with parameter for repulsion or magnet with a time counter... for example if 1 objet "on collision with X" i can put magnet with the time i want for the option magnet... the same with repulsion.
B
3
Posts: 6
Reputation: 212

Post » Tue Jun 18, 2013 12:50 am

You are complicating stuff

Just use the physics behavior !
(You could flesh the player controls , it's very basic but it does the job)

There's Repulsion and Attraction depending on the magnetwave angle

Cheers !
B
35
S
16
G
16
Posts: 2,222
Reputation: 16,589

Post » Tue Jun 18, 2013 10:38 am

Thanks! I use your tips for my project.


Note:a behavior/plugin with some options would be great ;)
B
3
Posts: 6
Reputation: 212

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 26 guests