Dev Log #2: controller and wheels

Figure 1Team Tamago

Hi again, this is Sida and here is dev log #2 about our VR based horror game: project hospital, and now it has been officially named “Shallow”! Cheers!

If you want to check the first dev log, please check out this link: https://www.heavyskymobile.com/?p=1459

Anyways, in this post I am mainly going to summarize some control logics behind the game, but before I begin, please allow me to talk about the progress since the last update.

First, other than the basic wheel chair control (which I will talk about later), now player can pick an item and inspect it in VR:

Figure 2 Player is examining the item

Also, I’ve added full time control system into the game using Chronos with some modification, now we can pause, fast forward or even rewind the game as we want.

Figure 3Time control system (Chronos)

Lastly, I’ve finished the basic VR controls including head tracking, Raycast item selection and play area detection. Although it is far way from fully finished, I still consider ourselves made a good progress into VR implementation.

Figure 4 Head tracking & item select

Figure 5 Play area detection

The next step is, import the grey box level, put the control systems in the real test and configure them by demand.

Well, enough of progress, let me introduce some logics behind the scene.

First, as I mentioned in first dev log, player is bounded to a wheelchair, the only way for him/her to move is by maneuver the wheelchair. Therefore, what we planned to do is to make a wheelchair simulator, where player must control each wheel separately.

As the figure 6 shown below, we use left joystick to simulate left wheel and right joystick to simulate right wheel. In detail, rotate the joystick does the same as rotate the wheel and press down the joystick is equal to the brakes.

Figure 6 The control scheme of wheelchair

However, one major problem is, how do you tell how fast the player rotates? Well, the solution I used is rather simple: record the joystick position (usually a vector 2, ex. (2,1)) between 2 frames (last and current) and divided by the time between frames.

Figure 7 The angle calculation diagram

In C# script, it will be:

Rotation speed = vector2. Angle(joystickPos1, joystickPos2) / Time.deltaTime;

 

Of course, you have to write a function to deal with the angle conversion when it passed 360 degree, I wrote a function to solve it, feel free to grab it:

float GetAngleDifference(float a1,float a2)

{


float ad = a1 - a2;


if(ad >= 300f)

{

ad = -(360f - a1) - a2;

}else
if(ad <= -300f)

{

ad = 360f - a2 + a1;

}


return ad;

}

 

Still, there is a problem with this method: the value it produced is unstable (the value varies in a huge range), in my case, it will cause the wheelchair move in a unpredict way. My solution is to calculate the average rotation speed instead of using instant rotation speed.

In detail, the average rotation speed is total rotation speed divided by total ticks and it will produce a stable result. Moreover, remember to reset those values when player released the joystick. (joystick position = 0)

Lastly, I will talk about some features regarding the wheel collider.

      1. Wheel collider is not an actual collider, so it does not work with hinges like hinge joint component. When attach a wheel collider to a game object, make sure there is a rigidbody attached to either itself or the parent game object.
      2. Wheel collider can not be added force, the only way to make it move is by modifying the “motorTorque” value (however, you can still add force to attached rigidbody tho).
      3. When turning, the car is always flipping over? Well, simply modify the center of mass value on attached rigidbody. For example, from (0,0,0) to (0, -2, 0), make it lower will significantly reduce the chance.
      4. How to turn your car? Just modify the steering angle value in the wheel collider, in my case, because the player has the ability to control each wheel individually, my method would be like the diagram below:

        Figure 8 Steering angle calculation
      5. Why my model in game is not rotating while the collider is? Well, there is detailed explanation on Unity’s online documentation: https://docs.unity3d.com/Manual/WheelColliderTutorial.html

That’s it! For the next dev log, I will talk about our VR implementation. See you then.

Sida

<

p style=”margin-left: 18pt;”>2016-10-21 19:56:01


Tagged: , ,

Leave a comment

Your email address will not be published.