• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Company
  • More Games
  • We’re Hiring!

Food Fight

Conquer the Food Goblin!

  • Home
  • About Us
  • The Game
  • Why it Works
  • Resources
  • News
  • Contact
    • Share Your Feedback!
Home › Development › Implementing A Conveyor Belt In VR (Part 2)

Implementing A Conveyor Belt In VR (Part 2)

Jun 27, 2018 |

Last week, we detailed how we wanted to implement a conveyer belt functionality within Food Fight, but we needed to determine the best approach that would benefit us without causing more programming issues. Here’s what we came up with!

The Best Solution Is Often The Simplest

We just needed to ‘trick’ the physics engine inside of Unity to do the conveyor actions for us. The physics engine is already running on every item with a rigidbody each frame anyway, so there is little to no performance cost either. To do this, we made a simple cube, sized it to the conveyor belt, and added a box collider as well as a rigidbody (set to kinematic with gravity off). We then removed the mesh renderer component, so the only thing the ‘physics’ object does is deal with the game physics.

And here’s all the code we need to put in our FixedUpdate() Method:

 if (isOn)
 {
    Vector3 position = rb.position;
    rb.position -= direction.normalized * settings.conveyorSpeed;
    rb.MovePosition(position);
 }

The Breakdown: What’s Happening

Unity’s Rigidbody component holds data for mass, velocity, rotation, and much more. It’s the main point where most programmers are going to deal with physics in Unity.

The best practice working with physics is to use FixedUpdate() which happens at regular intervals (by default every 0.02 seconds) regardless of processor load. This also will allow the conveyor to pause correctly since FixedUpdate is not called when Time.timeScale is zero, which is how we’re pausing our game and the rest of the physics.

We have a direction vector set inside the inspector. This should be a magnitude of 1 anyway, but we wanted to normalize it to make sure. We scaled that by the chosen speed from our player settings, which is a scriptable object we reference from all over the project. In our case, we ended up with a ‘speed’ setting of “only 0.02.” This doesn’t sound very fast at all, at first, unless you consider that it’s happening every frame.

The magic happens in the difference between setting a rigidbody’s position directly and using the MovePosition() method. When simply setting it with the ‘=’ operator, the rigibody is simply given the new position and will update to the new position at the start of the next frame. Generally, this is not a good idea because it does not calculate velocity or anything else that’s useful for doing physics when teleporting that object into the space.

The conveyor in action!

But, we use MovePostion — the “proper” way to move objects around with correctly calculated physics. And we do that to only move the rigidbody back to its original location.

The end effect is that the conveyor’s physics component never actually goes anywhere since the actual transform.postion never gets updated. But each frame has velocity data that is generated from the MovePosition method, and so in interacting with other objects it will get treated as if it’s moving very quickly underneath them. These objects then get ‘dragged’ along by the physics engines calculations for friction.

Takeaways and Conclusions

This approach has its limitations. The biggest is that it cannot be used on a curved path as-is except by splitting the physics elements into separate sections which would act separately.

There’s also no animation of the surface on the conveyor. This might be solved by animating the UV textures, but since we have it split up into different sections, syncing those up would be complicated.

Maybe the perfect way to do this would be with verlets, which can simulate cloth and other flexible materials, and with a customized shader that could animate the surface properly. But for the scope of what we needed, it’s important to recognize what is good enough to move on to the rest of the project.

In our play-testing so far with the conveyor, incorporating this makes two changes that offer more variety to game-play, especially for new players to VR. It provides a source of nutritious food and an easier path to power-ups. The functionality also allows the player to quickly practice with how the game physics will respond to the Oculus Touch controllers.

The other take away from this development is that an endless conveyor system of food is a pretty fun thing to play around with in VR. If you have an Oculus Rift, give our game a try and see what you think!


Category: Development Tagged: dev-blog virtual reality

About

Health Impact Studio logo

About Health Impact Studio

We are a dedicated team of developers and researchers with the mission to improve the health of individuals through novel technology including games, virtual reality, and role-playing simulations. We welcome input from the full range of stakeholders to create a customer experience with the broadest applicability to improving health outcomes.

Keep Reading

New Update – Food Fight V 1.1 Released!

Jul 01, 2019

Food Fight V 1.0 Released!

Dec 17, 2018

Wrapping Up Development – Part II

Sep 12, 2018

Previous Post: « Implementing A Conveyor Belt In VR (Part 1)
Next Post: Creating a Compelling Tutorial »

Primary Sidebar

Food Fight VR for Oculus Rift
Free!Get Food Fight Now!
  • New Update – Food Fight V 1.1 Released!
    Jul 01, 2019
  • Food Fight V 1.0 Released!
    Dec 17, 2018
  • Wrapping Up Development – Part II
    Sep 12, 2018
newsletter

Want to be kept up to date on the latest news?

Get Our Newsletter!

Footer

a product of
Health Impact Studio
a division of Clinical Tools, Inc

Get Food Fight
  • Copyright Guidelines
  • Privacy Policy
  • Terms of Service
  • Technology Requirements
  • 508 Compliance
  • Facebook
  • LinkedIn
  • Twitter
foodfight@healthimpact.studio

101 A Market St Chapel Hill, NC 27516
919-960-8118

We're Hiring!

Join the Development Team!

© 2023 · Clinical Tools, Inc · Log in

Sign Up for Our Newsletter!
  • Hidden

Thanks for signing up!

We’ll keep you up to date on the latest news!

In the meantime…

Check out our other amazing games available on the play store!

Get it on Google Play

And if you played the game…

We appreciate the feedback, it helps us improve our product for gamers to come!

Food Fight Satisfaction Survey