• Stars
    star
    118
  • Rank 299,923 (Top 6 %)
  • Language
    C#
  • License
    MIT License
  • Created about 7 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Unity3D tutorial project for drawing 2D physics shapes with the cursor

Draw 2D Physics Shapes in Unity3D

This tutorial project provides an example of how to draw shapes with the cursor in Unity similar to IncrediBots or Phun (now Algodoo).

The core logic of this project uses vertices specified from the cursor's coordinates to dynamically generate and configure a mesh, outline, and 2D collider.

Draw Shapes Preview

Project Overview

Requires Unity3D (tested with 2017.x, but should also work with 5.x)

.
β”œβ”€β”€ _Scenes
|   └── Main.unity              - The project's main scene
β”œβ”€β”€ Prefab
|   β”œβ”€β”€ Circle.prefab           - Circle physics shape
|   β”œβ”€β”€ Platform.prefab         - Stationary rectangular physics platform
|   β”œβ”€β”€ Rectangle.prefab        - Rectangle physics shape
|   β”œβ”€β”€ RotatingPlatform.prefab - Rotating rectangular physics platform
|   └── Triangle.prefab         - Triangle physics shape
└── Scripts
    β”œβ”€β”€ DrawCircle.cs           - Creates circle meshes and colliders
    β”œβ”€β”€ DrawController.cs       - Captures mouse input and creates shapes
    β”œβ”€β”€ DrawRectangle.cs        - Creates rectangle meshes and colliders
    β”œβ”€β”€ DrawShape.cs            - Base class for all shapes
    β”œβ”€β”€ DrawTriangle.cs         - Creates triangle meshes and colliders
    β”œβ”€β”€ ExplosionController.cs  - Generates explosion forces at the cursor
    β”œβ”€β”€ TestPolygon.cs          - Demonstrates how to draw polygon meshes
    β”œβ”€β”€ Triangulator.cs         - Generates triangles from polygon vertices
    └── Util.cs                 - Provides handy operations on vectors

Running the Project

To run the project, open _Scenes/Main.unity and click on the play button.

In the main scene there will be three buttons: square, circle, and triangle. Click on one of the buttons and then click 2-3 points in the game view to draw and release a physics shape. The shape will react to gravity and interact with other objects in the scene.