Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How can i create a fridge magnet physic on unity 3d?

Discussion in 'Physics' started by pedroarruda4991, Jun 28, 2023.

  1. pedroarruda4991

    pedroarruda4991

    Joined:
    Jan 9, 2021
    Posts:
    18
    When i tried, changing the option "is kinematic" whenever the magnet collides with the fridge, the object really gets static, but in weird position.

    I want to know if i can create a script that makes some type of snap, and the magnet works like on real life. Because with my script, the object kinda freeze, but without any force pulling the object to the fridge. How can i make something like real life magnets?

    That will be expansive to process if i had two magnets on the fridge?
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,362
    Add a fixed joint maybe? You could first add a force on the flat side of the magnet so it pushes itself towards the metal before adding the joint
     
    pedroarruda4991 likes this.
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    Of course you can. The collision information you get gives you the position and surface normal so you can align it at the correct position.
     
    pedroarruda4991 and DevDunk like this.
  4. pedroarruda4991

    pedroarruda4991

    Joined:
    Jan 9, 2021
    Posts:
    18
    I am pretty noob at that normal thing. I did a short research about contact points, but what i did instead was change the euler angles of the magnet when the collision ocurrs, so everytime that the player launches the magnet on the fridge, the magnet snap to the correct rotation. But i want to learn more about contact points. Thanks.
     
    DevDunk likes this.