EE308 LAB 4 Bobing software


Preface

This time, the Lab requires us to realize the bobing software of lab3, which is really a great challenge for us, because we have never been in contact with such a project before. And finally, at my insistence, my teammate Zongtan Li agreed to write this with Unity. In this assignment, Li is mainly responsible for UI construction and scene switching, while I am responsible for writing dice interaction code. Here is the information about my partner.

The Link of the Blog of my partnerEE308 Lab4: Pairing Coding for BOBING App
Partner’s MU STU ID and FZU STU ID19105690_831902209

Problem analysis and solution

1. Key functions

  • Random results of six dice

    The most important thing of bobing is to generate 6 random points. Although this is easy to realize with random numbers, we think that is very boring and the sudden points are unnatural. Therefore, it is a good choice to use a real physics engine, as shown in the figure below.

    figure_1.png

    Simulate the real Bobing situation, which makes people feel more surrogate.

  • Multiplayer gaming

    In lab3, we use the network to realize online connection, but due to the short time and insufficient ability of this experiment, we decided to use multiple people to play games with one mobile phone. The relationship between the number of people and the display is also very necessary. The game screen should show the total number of players, the number of players’ turn to operate, etc. The specific effect is shown in the figure below.

    figure_2.png

2. Difficulty

  • Modeling

    As a game engine, everyone knows the performance of unity. But if you take it as a modeling software, my evaluation of it is 😅. At the same time, it is not easy to make the material of the model. Without modeling experience, I spent two days building many different bowls and dice models. However, there are always various problems, such as the surface of the bowl is not smooth, and the hole representing the number of points on the dice sometimes gets stuck on the wall, which is very funny. I was not satisfied with the results every time. I once wanted to use maps instead of bowls and let the dice collide in a square box. Make the result look like a collision in a bowl. So how do I solve this problem? It’s simple: https://sketchfab.com .

  • Get dice points

    Using this simulation method can not control the final dice points, but also need to use the function to read the dice points. But this is not easy. First of all, when a dice can read its points, it must have stopped, so first write a script to judge the dice speed. When its speed is 0, calculate its points. But sometimes the instantaneous speed of the dice will also be 0. So I added a limiting condition. When the dice are stationary for 10 frames, it is considered that the dice are stationary, and the dice points can be read at this time. Then it is to judge the number of dice. The first method I think of is to judge the angle between the dice axis and the world axis. There are 6 positive and negative axes of XYZ axis, which just represent 6 faces. When the angle between an axis and the Y axis of the world coordinate is within a certain range, the number of points corresponding to the axis is considered to be the number of dice at this time. However, the positive and negative half axes of the axis meet this condition. Although a variable can be added to count the height of each face, I think it is very troublesome, so I abandoned this idea.

    Then, I thought, if I want to compare the height, why can’t it be higher than the height of all points? Which surface has the highest Y-axis coordinate, and the number of dice is the number of points corresponding to that midpoint. This method is easy to implement and has high accuracy. But then I found a problem, that is, sometimes the dice are stuck between the bowl wall and other dice. Generally speaking, the number of dice can not be counted at this time, but this method will return a specific value, which is inconsistent with the facts, so this scheme is also rejected by me.

    Finally, I decided to give full play to the powerful function of unity. I added a trigger to each side of the dice. When the dice were stationary, I detected which side triggered the contact with the ground. At this time, the dice points were the points of the face-to-face. If the number of triggers is not 1, it indicates that the state of the dice cannot be read normally. At this time, add a force to the dice to make it rotate again. Until it reads its points. The triggers of dice is shown in the figure below

    figure_3.png

    Key part code

    //Script of dice 
    if (canStart == false && Vector3.Magnitude(rigidbody.velocity) != 0)
    {
        isMoved = 0;
        for (int i = 0; i < 6; i++)
        {
            triggles[i].isTriggle = false;
        }
    }
    else if(isMoved < 10)
    {
        isMoved++;	//Record the number of frames the die is still
    }
    
    if (!canStart && Vector3.Magnitude(rigidbody.velocity) == 0 && isMoved >=10/*dice is still*/)
    {
        int count = 0;
        int diceface = -1;
        for (int i = 0; i < 6; i++)
        {
            if (triggles[i].isTriggle)
            {
                count++;
                triggles[i].isTriggle = false;
                diceface = i;
            }
        }
        if (count != 1)		//The number of triggers is not 1
        {
            Debug.Log("Abnormal dice state"+count.ToString());
            rigidbody.AddForce(1000, 1000, 1000);
            isMoved = 0;
        }
        else
        {
            result = triggles[diceface].point;	//point of dice
            canStart = true;
        }
    
    }
    
    //Script of trigger
    public bool isTriggle = false;
    
    void OnTriggerStay(Collider collider)
    {    
        if (collider.tag == "ground")
        {
            isTriggle = true;
        }
    }
    
  • The sound of dice colliding

    As a software that shakes dice, there is no soul without the sound of dice collision. I found many sounds of dice on the Internet, but I was not very satisfied. The audio file I finally used was the sound of small stones falling on the glass.

    At first, I thought it was very simple. Just play the sound of collision during collision. But during the test, I found that the sound was very chaotic and mixed together and the collision sound is the same. It sounds strange. My solution is: When the time interval between two collisions is very short, only one collision sound is emitted, and the size of the sound is related to the speed of the collision. The core code is as follows.

    float curTime, lastTime;	//Time of this collision, time of last collision
    void Start()
    {
        this.rb = GetComponent<Rigidbody>();
        this.lastTime = 0;
    }
    
    void OnTriggerStay(Collider collider)
    {
        curTime = Time.time;
        if (lastTime>0 && curTime - lastTime > 0.1)	//Filter collisions within 0.1 seconds
        {
            float pow = Mathf.Pow(Vector3.Magnitude(rb.velocity),2)/100;	//Strength of collision
            this.GetComponent<AudioSource>().volume = pow;
            this.GetComponent<AudioSource>().Play();
        }
        this.lastTime = curTime;	//The time of this collision is assigned to the last collision
    }
    
    

More code please see our Unity project: BoBing-Program


Working Environment

Since neither of us likes taking pictures, I put a picture of our late night communication.

figure_4.jpg

Late night liver explosion.🤗


Pair programming experience and gain

For this pair work, Li’s and my familiar things are different, so we have a problem in software selection. Because this is mainly graphical programming, we planned to use Processing at first, but we were not familiar with its usage. We also considered other ways of WeChat applet login, and finally decided to use Unity at my request. But the progress is still good after starting programming. Li is good at UI, I am good at code, and we perform our respective duties. No, we will help each other. If we spend more time, I think we will improve more details. However, we also have some differences. I buckle some small details, but Li doesn’t stick to details. As a result, many things Li does are not perfect, and my work speed is not fast.

For example, in the case of background music, we initially set that the concert will be played all the time and will not be interrupted when switching scenes. At first, it can work normally, but then we found a problem in the test. Although the music will not be interrupted, each time we switch to the main interface, the music files will not be destroyed, and the main interface comes with a music playback component, As a result, there will be multiple background music. After finding many methods, we can’t solve this problem perfectly. Finally, we chose a compromise. The background music will not be superimposed, but the components controlling the music can’t control the volume due to the lack of objects. This is still a bug for us. We will try our best to fix this bug. Sometimes, many things can’t satisfy you. You have to learn to accept it.

There are also windows for inputting the number of rewards and game rules. Now we may not be able to solve this problem, but after mastering sufficient knowledge, I will try to improve the software. After all, this is my first time to make a software, which is very meaningful to me.


Demo and software downloads

1. Picture display

  • Start interface

    figure_5.jpg

  • Mode selection

    figure_6.jpg

  • Game settings

    figure_7.jpg

  • Result display

    figure_8.jpg

  • Game interface

    figure_9.jpg

2. Demo video

link: https://pan.baidu.com/s/1dijMTucd0YCfd1B_o064zg

Passcode:7uqd

3. Software download

link: https://pan.baidu.com/s/1ulR4XnEgPygZDTWZAO4hpg

passcode: e7io


summary

1.PSP form for this work

Personal Software Process StagesEstimated Time (minutes)Actual time (minutes)
Planning180120
Estimate18653105
Development120120
Analysis120180
Design Spec3060
Design Review1020
Coding Standard60120
Design200840
Coding10001200
Code Review60180
Reporting60240
Test Report55
Size Measurement55
Postmortem & Process Improvement Plan1515
Total18653105

2.Personal feelings

I think this lab is very challenging for me. It is undoubtedly difficult to challenge a field I haven’t touched before in a time limit of a week for the first time, but as long as I conquer the past, I will have a great sense of achievement. Although our software still has many vulnerabilities, so I still need to learn how to solve these problems. If you have some opinions or can solve my bugs, please contact me. My email is 2579538675@qq.com.


The Link Your ClassEE308 MIEC
The Link of Requirement of This AssignmentLAB 4 Second pair programming assignment
MU STU ID and FZU STU ID19103387_831902225
Teammate’s MU STU ID and FZU STU ID19105690_831902209
Teammate’s blog linkEE308 Lab4: Pairing Coding for BOBING App
Project linkBobing software
Video demo linkBaidu Netdisk link ( passcode: e7io )
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值