Challenges
The most challenging aspect of creating this system was managing the conditions that restricted when the magnetic abilities could trigger, as specified in the design document. The core issue turned out to be that the object’s linear velocity was not reset to zero after the trigger was released. This created a timing gap in the script’s execution, causing the ability to activate outside its intended limits and making it seem as though the conditions themselves were failing.
An additional complication came from the fact that the game object used a dynamic rigidbody, which allowed the player to physically push it while using the magnetic abilities.
Solution
To address the issue, I first used a small rectangular BoxCollider2D with a trigger to detect when the player was too close to the game object. If the player entered this range, the object’s X-axis was locked and the player was prevented from using magnetic abilities. However, this approach limited player freedom by forcing them to maintain a certain distance in order to use the abilities.
Eventually, the game object was converted into a kinematic rigidbody. The previous proximity check was adapted so that if one kinematic object came too close to another, the player would be blocked from pushing into them but still allowed to pull the object toward themselves.
This part of the script is to detect all magnetic gameobjects within the range then using DOT product to determine if the magnetic game object is Infront (within a certain threshold) of the player.
If so then he will choose the closest gameObject, and retrieve data like rigid body from it .
Here is where the gameObject is getting pull or push, as this is required to base it on the current form of the player and the type of game object.
Here is if the player is in red or blue form , a line of circle VFX will appear between the player and game object to show a connection.
If the player use the abilities then it will change to a line of arrow VFX, with the direction either moving towards the game object or towards the player.
What I Learned
Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth.
What to improve
Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth.
Results
