Tips for creating a magnet/magnetic field
anithmuk
Member Posts: 235
Hey, so a while back I was trying to make a nice little magnet type actor for my game. I searched the forums and found a few people wanting the same sort of effect but I couldn't find any good answers. So just for future reference I thought I'd post what I did.
I created 2 real game attributes 'mag x' and 'mag y' and created an actor 'magnet'. I put in 2 change attributes to change mag x and mag y to self position x & y. I went into my player actor and said: When player position x = mag x + 60 or mag x - 60 (and then did the same for the y positions and values), accelerate to position mag x, mag y with acceleration 1000 (obviously all numbers are adjustable for the desired effect).
I already had a 'player accelerate' boolean game attribute, so I used that and turned it off when the player was in the vicinity of the magnet and turned it back on when it got out of the magnetic field. In certain situations I allowed the player's acceleration to continue even in the magnetic field to create a cool parabolic effect as it passed the magnet. This set up also means that as the player gets closer to the magnet, the magnet's pull gets greater and greater and then fades as the player moves away, so it works fairly realistically.
This has a number of uses, personally I used it to allow the player to 'jump' great distanced by using the pull of the magnet to give the player a bunch of momentum.
Anyway, hoped this helped anyone
I created 2 real game attributes 'mag x' and 'mag y' and created an actor 'magnet'. I put in 2 change attributes to change mag x and mag y to self position x & y. I went into my player actor and said: When player position x = mag x + 60 or mag x - 60 (and then did the same for the y positions and values), accelerate to position mag x, mag y with acceleration 1000 (obviously all numbers are adjustable for the desired effect).
I already had a 'player accelerate' boolean game attribute, so I used that and turned it off when the player was in the vicinity of the magnet and turned it back on when it got out of the magnetic field. In certain situations I allowed the player's acceleration to continue even in the magnetic field to create a cool parabolic effect as it passed the magnet. This set up also means that as the player gets closer to the magnet, the magnet's pull gets greater and greater and then fades as the player moves away, so it works fairly realistically.
This has a number of uses, personally I used it to allow the player to 'jump' great distanced by using the pull of the magnet to give the player a bunch of momentum.
Anyway, hoped this helped anyone
Comments
one of those great tips that starts a developer generating ideas for apps to use it in!
MH