Skip to content

ntoulasm/crowd-simulation-unity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Magnetic Crowd Simulation for Unity

Crowd Simulation Screenshot

A lightweight crowd simulation project built in Unity, implementing a Magnetic Force Model (based on Coulomb's Law). The project is optimized for Mobile VR, focusing on maintaining high frame rates on mobile hardware while simulating moderate crowd sizes.

🚀 Features

  • Magnetic Force implementation: Agents act as "charged" particles, naturally avoiding each other and obstacles through magnetic-like repulsion.
  • Coulomb's Law based physics: Uses inverse-square law forces to manage agent spacing and collision avoidance.
  • Mobile VR Optimized: Specifically tuned for devices like Google VR, ensuring smooth performance even with 200+ agents.
  • Intelligent Obstacle Avoidance: Agents dynamically steer around static and dynamic obstacles using calculated repulsive potential fields.
  • Path-based Navigation: Agents follow a sequence of randomly assigned destinations to create realistic movement patterns.
  • Dynamic Animation Controller: Character animations (walk speed, leg movements) are synced with the agent's physical velocity.

⚡ Performance

This simulation is designed to balance physical realism with mobile hardware constraints:

  • Benchmark: Achieves smooth performance with up to 200 agents on mobile hardware (e.g., Poco F1) without noticeable delay.
  • Complexity: The force calculations run at $O(N^2)$ for agent-agent interactions and $O(N \times M)$ for obstacles.
  • Mobile Efficiency: Performance is achieved through efficient C# vector math and localized force calculations.

🛠️ Technical Details

The simulation treats agents as particles with "magnetic charges" ($Q$). The motion of each agent is governed by the summation of three primary force vectors:

  1. Desired Force (Attraction): An attractive force pulling the agent toward its current destination at a controlled speed.
  2. Magnetic Repulsion (Agents): Based on Coulomb's Law ($F = k \frac{Q^2}{r^2}$), this force prevents agents from colliding. The variables k and Q in the code define the strength and range of the repulsion.
  3. Obstacle Repulsion: A specialized force that calculates the closest point on any obstacle and applies a magnetic push away from it, ensuring agents stay within navigable paths.

Implementation

  • Agent.cs: Contains the core math for the inverse-square law force calculations and velocity integration.
  • Manager.cs: Handles spawning, destination assignment, and global simulation parameters.
  • Obstacle.cs: Provides proximity and collision data for the agent's force calculations.

📸 Screenshots

Overview Closer Look
Screenshot 1 Screenshot 2

💻 Requirements

  • Unity 2018.x or later (Recommended for compatibility with Google VR assets)
  • Android/iOS SDK (For mobile deployment)
  • Google VR SDK (Included in project)

🏗️ Getting Started

  1. Clone the repository:
    git clone https://github.com/ntoulasm/crowd-simulation-unity.git
  2. Open the Unity folder project in Unity Hub.
  3. Open the main scene in Assets/Scenes.
  4. Press Play to see the simulation in action.

📄 Documentation

For more detailed information, check the docs folder which contains:

  • CrowdSimulationForMobileVR.docx: Full technical report explaining the magnetic field approach.
  • CrowdSimulationForMobileVR.pptx: Presentation slides.

About

This project was developed as part of a University curriculum focusing on Computer Graphics. The goal was to implement an efficient crowd simulation model capable of running on mobile-integrated VR headsets (like Google VR) without sacrificing the physical realism of agent interactions.

Topics

Resources

Stars

Watchers

Forks

Contributors