Shoot Character Towards Magnets

How do I…

Hey guys! I’ve decided to implement a new idea into my game to make it more fun and interesting. The idea is, that within a certain distance to a ‘magnet’, a player can press a button and ‘shoot’ towards it, like a bullet going down the barrel of a gun. After colliding with the magnet, the player would arc away, and maybe press a button to collide with another magnet.

Like this:

What is the actual result

I’ve been trying to use forces, but it doesn’t seem to be working at all. I’m trying to do something similar to Ori and the Blind Forest, example here:

Related screenshots

It probably isn’t surprising that this code isn’t working. It seems the only way I can get the acceleration I want, is by making a permanent force. But when all forces are removed, obviously any speed built up by the permanent force disappears. Also by using this code, if I’m not angled in a specific way, I could shoot right past the magnet and not hit it at all, making precision movements impossible. I want to use these eventually for tougher puzzles in the game that will require these sort of tight precisions.

Any suggestions on how to best go about this sort of thing? Or perhaps an alternative idea that can do a similar output? Thank you so much!

Is the player reaching the magnet. Maybe it needs more force or time. I think the magnet =1 condition needs a trigger once . It looks like it’s repeatly adding a permanent force and a wait. The wait actions will build up at one additional wait per frame for almost a second and then continually set the magnet to 2 until the built up waits are executed.

1 Like

Okay thank you so much! I actually ended up scrapping the idea- I realized magnets wouldn’t work with the sort of game I’m attempting.

1 Like