rvo collision avoidance in unity 3d - computing...

7
RVO Collision Avoidance in Unity 3D David Cherry Abstract Reciprocal Velocity Obstacles (RVO) method was used to produce collision avoidance for crowd simulations generated using the game engine Unity 3D. Smooth collision avoidance was produced for multiple agents in the same environment by using RVO collision avoid- ance method. There are three methods for generating crowd simulation using RVO col- lision avoidance in this experiment. The first method consists of taking user input on the starting position, goal position, and speed of each agent to be simulated and rendered in the virtual environment and the information will be exported to a file. The second method is loading a pre-existing file into Unity for the information to input for the simulation. The third method was to start with only one agent that continuously moves to ran- dom goal positions and can be duplicated to produce more agents in his environment. This experiment was combined with another collision avoidance method called predictive forces collision avoidance. An user inter- ace was developed to choose which collision avoidance should be displayed and the spe- cific method for the enviornment to be simu- lated and rendered in Unity. 1 Introduction Crowd Simulation consists of producing movement of a large number of entities, or characters within a virtual environment. A few uses of crowd simulation consist of being used to create emergency evacuation simu- lations, video game crowd AI behavior, and recreating places in the past to show how people would have behaved. The characters used in the virtual environment are known as agents and each one is given their own AI to function in their respective environment. They are given a set path, destination, and specific behaviors based on their unique pro- gramming. One major issue that typically must be addressed when simulating multiple AI in the same environment is collision avoid- ance. Each agent must be able to detect ob- jects or another agent, and then in turn be able to veer off the path in a smooth man- ner to prevent collision. If there is a case where two agents are both moving towards each other, then they must also behave in a way to avoid collision in an efficient manner. This summer at the University of Min- nesota, I focused on implementing the colli- sion avoidance method called Reciprocal Ve- locity Obstacles (RVO) in the game engine Unity. Unity is a game engine built in with a powerful rendering engine designed with tools to create an interactive 3D environment [Creighton, 2010]. Unity has a drag and drop environment for creating games and can be programed in JavaScript, C, and Boo. The high level approach we took is outlined in Figure 1. Information on objects in Unity would be taken from the environemnt mean- Page 1

Upload: doanlien

Post on 12-May-2018

259 views

Category:

Documents


0 download

TRANSCRIPT

RVO Collision Avoidance in Unity 3D

David Cherry

Abstract

Reciprocal Velocity Obstacles (RVO) methodwas used to produce collision avoidance forcrowd simulations generated using the gameengine Unity 3D. Smooth collision avoidancewas produced for multiple agents in the sameenvironment by using RVO collision avoid-ance method. There are three methods forgenerating crowd simulation using RVO col-lision avoidance in this experiment. The firstmethod consists of taking user input on thestarting position, goal position, and speed ofeach agent to be simulated and rendered inthe virtual environment and the informationwill be exported to a file. The second methodis loading a pre-existing file into Unity forthe information to input for the simulation.The third method was to start with onlyone agent that continuously moves to ran-dom goal positions and can be duplicatedto produce more agents in his environment.This experiment was combined with anothercollision avoidance method called predictiveforces collision avoidance. An user inter-ace was developed to choose which collisionavoidance should be displayed and the spe-cific method for the enviornment to be simu-lated and rendered in Unity.

1 Introduction

Crowd Simulation consists of producingmovement of a large number of entities, or

characters within a virtual environment. Afew uses of crowd simulation consist of beingused to create emergency evacuation simu-lations, video game crowd AI behavior, andrecreating places in the past to show howpeople would have behaved. The charactersused in the virtual environment are knownas agents and each one is given their own AIto function in their respective environment.They are given a set path, destination, andspecific behaviors based on their unique pro-gramming. One major issue that typicallymust be addressed when simulating multipleAI in the same environment is collision avoid-ance. Each agent must be able to detect ob-jects or another agent, and then in turn beable to veer off the path in a smooth man-ner to prevent collision. If there is a casewhere two agents are both moving towardseach other, then they must also behave in away to avoid collision in an efficient manner.

This summer at the University of Min-nesota, I focused on implementing the colli-sion avoidance method called Reciprocal Ve-locity Obstacles (RVO) in the game engineUnity. Unity is a game engine built in witha powerful rendering engine designed withtools to create an interactive 3D environment[Creighton, 2010]. Unity has a drag and dropenvironment for creating games and can beprogramed in JavaScript, C, and Boo. Thehigh level approach we took is outlined inFigure 1. Information on objects in Unitywould be taken from the environemnt mean-

Page 1

ing from User input or a data file with theinformation. The simulation based on thecoding would begin and Unity would renderthe scene, objects and information so thatthe User would be able to view models, envi-ronments in a virtual environment.

Figure 1: The flow chart or retrieving in-formation from the environment(user inputor from a data file), running simulation, andrendering in Unity

Unity 3D is growing in popularity amongstdevelopers and can potentially be used in invirtual environments. Unity is compatiblewith software such as Mitsuba and blenderto allow created models to be placed intothe game engine environment. There is aproject going on at the University of Min-nesota to integrate Unity into a virtual envi-ronment to recreate ancient life in Greece.Theyll be able to produce structures, cal-culate the amount of people that could fit,and recreate people functioning in their en-vironment. If these people, the agents inthe virtual world, were walking around thecity, then they would need to know how toavoid collision to continue on their path. Thisis where the RVO for multi-agents methodcould be applied. Unity has a variety of usessuch as gaming, simulations, and even design.Unity has been used for robotic design bycreating a functional virtual robot in Unity,then actually creating it based on the Unitymodel [Mattingly et al., 2012]. Other usesfor Unity include application developmentthat can port to iPhone, Android, and PCs.

2 Previous Work

2.1 Crowd Simulation for prac-tical use

Crowd simulation techniques have been usedto create emergency situation simulations. Amixture of social sciences and computer im-plementation of modeling using multi-agentsystems with their own programming behav-ior was used to reproduce emergency situa-tion behavior. One recurring issue is mea-suring how a group of people would reactin a real emergency panic situation. To re-ceive highly accurate results, it would re-quire placing people in real emergency sit-uations. However, making observations frompedestrian crowds could assist by showing thesame patterns for reproducing the behavior.A person, that does not know the structureof the building as well, would focus on find-ing the nearest escape route, would follow thecrowd and their velocity would rapidly in-crease [Almeida et al., 2013]. This scenariois illustrated in Figure 2.

Figure 2: Crowd trying to escape fromsmoke-filled room [Almeida et al., 2013]

There have been specific tools created togenerate environments with emergency evac-uation environments. One tool called Col-labmap has been created to generate en-vironments, this could be combined withcrowd simulation methods to create vir-tual scenarios, the effectiveness, and howlong it would take to evacuate the building

Page 2

[Ramchurn et al., 2013]. Some crowd simu-lation software is made for specific circum-stances outside of buildings such as an evac-uation ”from an area under a terrorist bombattack” [Shendarkar et al., 2006]. The cre-ators of that experiment focused on their ownBDI (belief, desire, intention) agent frame-work they’ve created.

There are three main reasons for devel-oping computer simulations for crowd be-haviors: first to test scientific theories andhypotheses; second, to test design strate-gies; third, to create phenomena about whichto theorize [Almeida et al., 2013]. An un-derstanding of crowd behavior is needed toreplicate the behaviors of a real crowd forcrowd simulation. Each agent also has var-ious attributes to determine their behaviorwhich consists of state, speed, vision, re-action time, collaboration, insistence, andknowledge [Almeida et al., 2013]. Vision isthe aspect that depends on detecting obsta-cles and other agents. This is where collisionavoidance would be applied due to the detec-tion aspect.

The practice of crowd simulation basedon cognitive, psychological, and sociologicalfactors stem from the works of Craig W.Reynolds [Reynolds, 1987]. This paper fo-cused on how he implemented behaviors ofa flock of birds. His goal was to capture thebehavioral aspects consisting of their move-ments to interactions. Steps are being madeto expand upon his ideals on cognitive be-haviors to try and govern what a charac-ter knows and how knowledge is acquired[Funge et al., 1999]. This can stem back tothe knowledge aspect for emergency evacua-tions because if a character knows the fastestmethod to escape, then he would not followthe crowd in a panic similar to the situationdisplayed in Figure 2.

2.2 Methods for Real-TimeMulti-Agent Navigation

Reciprocal Velocity Obstacles (RVO) is aconcept for local reactive collision avoid-ance which implicitly assumes that the otheragents make a similar collision-avoidancereasoning[van den Berg et al., 2008]. Eachagent contains information on all of the otheragent’s current position, velocity and exactshape. Instead of giving each agent a new ve-locity to completely avoid collision with theother agents velocity obstacle, RVO intro-duces a method of taking the average of thecurrent velocity and the velocity outside ofthe other agent’s velocity obstacle. This willallow the agent to choose the velocity closestto its current velocity. Both agents will beable to take the closest velocity to their pre-ferred velocity resulting in both agents eachtake an equal share of the work to success-fully avoid collision. RVO is not only limitedto being used in a virtual environment. Colli-sion avoidance is also a fundamental problemin robotics [van den Berg et al., 2011].

The problem of having collision free motionand smooth movement for multiple roboticagents are still prevalent in the world to-day. Optimal reciprocal Collision Avoid-ance is just one example of a collision avoid-ance method that was used for the multiplerobotic agent navigation [Snape et al., 2010].This method and RVO both stem from Veloc-ity Obstacles (VO) to avoid future collision[Fiorini and Shiller, 1998].

3 RVO in Unity

The goal for my project this summer was toimplement a fully functional project in unitythat could implement reciprocal velocity ob-stacles (RVO) collision avoidance to multipleagents. I started to do this by first creatingan environment that consisted of six cubesand a flat terrain to begin working. In the

Page 3

scripting, I coded the various formulas fromthe RVO paper to implement them into Unity[van den Berg et al., 2008].

First, I began learning Unity’s mechanicsand how to create and move objects. Insteadof human models, I began with using cubesas game agents. After figuring out how tomanage objects and scripts using the UnityEditor, I started to implement RVO formulasin code.

D = |vpreferred − vtest| (1)

Equation 1 contains variable D which rep-resents the magnitude of the preferred veloc-ity minus an arbitrary test velocity. Veloci-ties are sampled to find the best velocity totake for avoiding collision. I found that test-ing 100 samples of arbitrary velocities wasenough to produce a nice motion. This valueis added into Equation 2 for the RVO for-mula.

Score = ((w/(τ + 0.001)) +D) (2)

The score has a time returned to it. Thesmallest time for the score determines whichtest velocity should be taken.

Equation 2 contains the Score variable inmy script. RVO finds the minimum time ofcollision and then finds the best velocity thatis closest to its own to avoid collision. Thisscore function will have a time returned toit and the smallest time returned to scorewill indicate that the test velocity used forcalculating that score is the best velocity totake for collision avoidance. The τ representsthe time to collision and contains the closesttime to collision for each agent. The w vari-able is a specific number given to determinethe importance on having the agent focuson collision avoidance or the goal position.The higher the w value, the more the objectwill focus on heading towards the goal. Thelower the w value, the more the object willbe geared towards collision avoidance. Given

the above information, we can find how longthe time is to a potential collision as follows.First, we must compute the values for Equa-tions 3, 4, 5 as shown below.

a = (|vtest − vobj|) ∗ (|vtest − vobj|) (3)

b = 2 ∗ ((|(vtest − vobj)|) · (Pcur ∗ Pobj)) (4)

c = |(Pcur − PobJ)|2 − (rcur ∗ robj) (5)

Equations 3, 4, 5 each contain informationon the current object position (Pcur), the ap-proaching object position (Pobj), the radiusof both objects (rcur, robj), and the arbitrarytest velocity (vtest). Object Velocity (vobj)in Equation 3 refers to the approaching ob-jects current velocity while the arbitrary ve-locity (vtest) being tested for collision avoid-ance. Equations 4 and 5 have informationabout the current positions of both objectsto give accurate information on the time tocollision. These values will be placed into thequadratic formula for calculating the time tocollision.

(t1, t2) =−b±

√b2 − 4ac

2a(6)

Where t1 and t2 are the positive and negativesolutions.

τ = min(t1, t2) (7)

The min takes in the smallest non-negativevalue.

TAs a result of the quadratic formula, twotimes may be produced to represent the timeto collision. If both of these values are pos-itive, then the lesser value will be the onestored to the minimum time to collision. Ifboth of these values are not positive or bothare negative, then there is a condition set to

Page 4

not accept the time value because this im-plies that the objects would not collide. Ifone value is negative and the other is posi-tive then that means it is currently colliding.The smallest time from the two positive val-ues are stored into τ from Equation 7 to rep-resent the closest time to collision. After cod-ing fully functional RVO method into Unity,I ran the code with cubes show by Figure 3below.

Figure 3: Cubes with random goal positionsusing RVO collision avoidance

The cubes were given a randomized po-sition and after they reached a small dis-tance away from their goal position, theywere given another goal position to navigateto. When two cubes were about to collide, us-ing RVO collision avoidance, they were ableto detect each other and avoid collision tocontinue towards their goal position. Thenext task assigned was to be able to spec-ify the cube’s starting position, ending po-sition, and speed as input then to run thatin the game environment while still havingRVO applied. I created a GUI interface al-lowed users to create their own text files withthis format displayed in Figure 4.

The user interface that was created inUnity exports a file with this format andtakes that information to create the speci-fied objects, then lead them towards theirgoal position. The next step was to moveonto actual animated models instead of us-ing cubes as my agents. The human modelswere imported inside of unity to replace thecubes. One issue was adjusting the models toface their current position and animating the

Figure 4: The format for files to be imple-mented in Unity

models to walk, but this was solved by us-ing a rotation method implemented in Unity.After both issues were resolved, I finally haveRVO collision avoidance with human agents.This is shown in Figure 5 below.

The next task was to create a button theuser interface that will allow a previously cre-ated file to be read and another button thatwill allow the original random goal positionprogram to run. Implementing the read afile method was similar towards reading thecreated file which lead to no difficulties. Therandom goal position assigned to each objectswas already created and also integrated intothe program. This scene begins with one in-dividual and to duplicate that individual, Ihave the user press ’T’. The starting scene is

Page 5

Figure 5: Overhead view of RVO collisionavoidance

shown in Figure 6 and the scene with dupli-cated instances is shown in Figure 7.

Figure 6: Starting with one agent with ran-domized goal

Figure 7: Duplicate of agents with random-ized goals using RVO collision avoidance

The final task was to combine myproject with Jassiem Ifill, another DREUstudent from my lab, who was imple-menting another crowd simulation tech-nique, predictive force collision avoidance[Karamouzas et al., 2009]. We had to inte-grate both of our projects into one projectthat was supported by the same user inter-face. This gives the user options of observing

the RVO collision avoidance method or thepredictive force collision avoidance method.After combining our projects, we created afully functional project with collision avoid-ance in the same type of environment usinghuman animated agent.

4 Conclusion

The complete project is able to run bothreciprocal velocity obstacles collision avoid-ance and predictive forces collision avoid-ance. There are differences in how the codeoperates in both projects; however, both areable to create and run a file with the userspecifications for the human agents while be-ing able to avoid collision. They also are ableto read a previously made text file as long asit has the correct format for being read. Inthe RVO method, there is an option to du-plicate from the original human agent to addmore human agents all with arbitrary start-ing positions, and goal positions in the sameenvironment with RVO collision avoidance.

One limitation for Unity is the amount ofagents that can move and be displayed on thescreen while running smoothly. Unity tendsto slow down a great deal when to manyagents are placed in the same environemnt.For future experiments RVO collision avoid-ance could be used in a larger custom envi-ronment such as a city. Many different agentmodels and stationary obstacles could be putinto place to further test RVO collision avoid-ance. Another feature to create after gener-ating this environment is a first person usercontrolled character. This will allow a closerview on how smooth the RVO collision avoid-ance s while the other agents avoid collisionwith the user’s controlled agent.

5 Acknowledgements

I’d like to thank Dr. Stephen Guy for hisguidance, assistance, and methods for RVO,

Page 6

Unity and the project as a whole. I alsowould like ot thank Dr. Ioannis Karamouzasfor his help with Unity and crowd simula-tions.

References

[Almeida et al., 2013] Almeida, J. E., Ros-seti, R. J., and Coelho, A. L. (2013).Crowd simulation modeling applied toemergency and evacuation simulations us-ing multi-agent systems. arXiv preprintarXiv:1303.4692.

[Creighton, 2010] Creighton, R. H. (2010).Unity 3D Game Development by Example:Beginner’s Guide. Packt Publishing.

[Fiorini and Shiller, 1998] Fiorini, P. andShiller, Z. (1998). Motion planning in dy-namic environments using velocity obsta-cles. The International Journal of RoboticsResearch, 17(7):760–772.

[Funge et al., 1999] Funge, J., Tu, X., andTerzopoulos, D. (1999). Cognitive mod-eling: knowledge, reasoning and planningfor intelligent characters. In 26th annualconference on Computer graphics and in-teractive techniques, pages 29–38.

[Karamouzas et al., 2009] Karamouzas, I.,Heil, P., van Beek, P., and Overmars,M. H. (2009). A predictive collision avoid-ance model for pedestrian simulation. InMotion in Games, volume 5884 of LectureNotes in Computer Science, pages 41–52.Springer.

[Mattingly et al., 2012] Mattingly, W. A.,Chang, D.-j., Paris, R., Smith, N., Blevins,J., and Ouyang, M. (2012). Robot de-sign using unity for computer games androbotic simulations. In Computer Games(CGAMES), 2012 17th International Con-ference on, pages 56–59. IEEE.

[Ramchurn et al., 2013] Ramchurn, S. D.,Huynh, T. D., Venanzi, M., and Shi, B.(2013). Collabmap: crowdsourcing mapsfor emergency planning.

[Reynolds, 1987] Reynolds, C. W. (1987).Flocks, herds, and schools: A distributedbehavioral model. Computer Graphics,21(4):24–34.

[Shendarkar et al., 2006] Shendarkar, A.,Vasudevan, K., Lee, S., and Son, Y.-J.(2006). Crowd simulation for emergencyresponse using bdi agent based on virtualreality. In Simulation Conference, 2006.WSC 06. Proceedings of the Winter, pages545–553. IEEE.

[Snape et al., 2010] Snape, J., Guy, S. J.,van den Berg, J., and Manocha, D. (2010).Smooth coordination and navigation formultiple differential-drive robots. In Proc.IEEE RSJ Int. Conf. Intell. Robot. Syst,pages 1–13.

[van den Berg et al., 2011] van den Berg, J.,Guy, S. J., Lin, M., and Manocha,D. (2011). Reciprocal n-body collisionavoidance. In Cedric Pradalier, RolandSiegwart, and Gerhard Hirzinger (eds.),Robotics Research: The 14th InternationalSymposium ISRR, volume 70 of SpringerTracts in Advanced Robotics, pages 3–19.Springer-Verlag.

[van den Berg et al., 2008] van den Berg, J.,Lin, M. C., and Manocha, D. (2008). Re-ciprocal velocity obstacles for real-timemulti-agent navigaiton. In IEEE Inter-national Conference on Robotics and Au-tomation (ICRA).

Page 7