Real-Time Track Edits | Building Roller Coasters | Voster Coaster

in #utopian-io6 years ago (edited)

Repository

https://github.com/ajayyy/VosterCoasterVR/

What is Voster Coaster?

Voster Coaster is a VR game where you build roller coasters. I plan on making it a theme park tycoon game in the future as well.

Made the height of track pieces uniform for turns

Before, the inside turn would be scaled to the correct height:
image.png

Now, the outside turn is:
image.png

This is much more useful, as it makes the total height uniform, and will help when combining turn pieces with normal pieces.

Fixed issue with track pieces becoming misaligned at certain angles

For angle of 27 degrees before the change:

image.png

After:
image.png

How?

To fix this, I had to think of the track piece as one section of a full circle
image.png

Then, I can use SOH CAH TOA to know that the Cos of the angle B (in this case 90 - 27 as shown in the diagram above), is equal to the adjacent divided by the hypotenuse.

This means sinB = O/H, cosB = A/H, tanB = O/A (These are the lengths of the sides, Opposite and Adjacent of the angle, and the Hypotenuse).

The angle is determined from the total angle of this track piece, but then it has to be 90 - that angle, as shown in the image above. The known angle is angle A, and angle A is equal to 90 - B.

The hypotenuse side is the radius of the circle.

//calculate the full angle this track piece gets to
float totalAngle = 90 - adjustmentAngle.y * 9f;

 //radius of the outside circle (SOH CAH TOA, cosA = a/h, h = a/cosA)
float radius1 = Mathf.Abs(sizes[i]) / Mathf.Cos(totalAngle * Mathf.Deg2Rad);

Now, the proper radius is calculated instead of just assuming that the full height is the radius (as that would only work for a 90 degree turn).

Real-time track adjustment

realtime-track-adjustment.gif

This was done by creating a function to reset the track completely. This makes it so that you can modify it again.

This works, but is very inefficient, requiring the whole mesh to be reset every frame just to be adjusted again.

So, I later changed it again. Now, when adjusting the mesh of the track, it does not do any math relative to the positions (transform.localPosition *=) but instead sets it to the default (transform.localPosition = defaultBonePosition *).

This, along with setting the angle instead of adding to it, and saving the original size to attempt to scale all track pieces too removes the need to reset the track piece every frame when changing the angle.

GitHub Account

https://github.com/ajayyy/

Pull Requests

https://github.com/ajayyy/VosterCoasterVR/pull/6
https://github.com/ajayyy/VosterCoasterVR/pull/7
https://github.com/ajayyy/VosterCoasterVR/pull/8

Sort:  

Thanks for the contribution, @ajayyy! I would recommend increasing the amount of work for future contributions, as it's pretty low for this one. Other than that the code looks fine and it is well-commented.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

My next update is going to be big, I hope that is better. I'll make sure to do more work in future. Thanks for reviewing!

Hey @ajayyy
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Contributing on Utopian
Learn how to contribute on our website or by watching this tutorial on Youtube.

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Hello ajayyy!

Congratulations! This post has been randomly Resteemed! For a chance to get more of your content resteemed join the Steem Engine Team

Coin Marketplace

STEEM 0.20
TRX 0.15
JST 0.030
BTC 65185.94
ETH 2630.94
USDT 1.00
SBD 2.83