Seminar_Cable_Joints_Unity/README.md

1.9 KiB

Cable Joints implementation in Unity

Running:

  • Load project in Unity
  • Select a scene from the file explorer in "Assets > Scenes"
  • Enable Gizmos using the button in the top right of the game preview
  • Press the play button

Code Structure

File Description
CableJointsAlgorithm.cs Main Algorithm Implementation
Controller.cs Sets up the scene, creates Unity Game Objects
RollerProperties.cs Contains properties for each part of the Cable
Extensions.cs Useful extension methods

Creating a scene:

An effort was made to simplify creation of new scenes as much as possible and create most required objects in code instead.

  • Create a new scene in unity
  • Add the controller component to any object (e.g. the Main Camera)
  • Add rollers using Right click > 2D Object > Sprites > Circle
  • Other shapes can be added using the same menu
  • Add the RollerProperties Component to all objects which should be connected by the cable and adjust the settings:
    • Start: set for one of the ends of the cable
    • Clockwise: determines the side the cable is running around the object
    • Link To: Select the next game object the cable should be connected to
    • Movement: Rotatable and Powered should only be used for circles and represent rollers. Fixed and Free can be used for any shape
    • Use fixed attachment point: If set to true the object is not viewed as a roller, but a point attachment instead (e.g. weights)
  • Objects not connected by cable (e.g. Floor) can be created by adding an sprite with a collider.
  • Mass is calculated based on area
  • Press 'T', to toggle powered wheels on and off.