In-depth introduction to game algorithms (4)-unity3d algorithms (2)-mobile ball, in-depth introduction-unity3d

Source: Internet
Author: User

In-depth introduction to game algorithms (4)-unity3d algorithms (2)-mobile ball, in-depth introduction-unity3d

Declare a gameobject object to implement a script for multiple objects

#pragma strict//code:myhaspl@myhaspl.com//date:2014-08-12var rotate_object:GameObject;var translate_object:GameObject;var fuhao:int;fuhao=-1;function Update () {   if (rotate_object!=null){       rotate_object.transform.Rotate(1,1,-1);   }   if (translate_object!=null) {            if (translate_object.transform.position.y<9 ){           fuhao=1;       }       if (translate_object.transform.position.y>15)        {           fuhao=-1;       }       translate_object.transform.Translate (0,fuhao*0.1,0);   }}

All contents of the good AI Park blog is original, if reproduced please indicate the source http://blog.csdn.net/myhaspl/

The following layout is displayed in unity3d:

The running effect is shown in the following link:

Http://mygame.myhaspl.com/test2/test2.html

Update () and FixedUpdate () are automatically called cyclically during Update in the game.

Update is called every time a new frame is rendered. FixedUpdate is executed at a fixed interval and is not affected by the Frame Rate of the game. It is generally used in steel.

Steel body. If gravity is not checked, move the ball side down:

# Pragma strict

Vartranslate_object: Rigidbody;

FunctionFixedUpdate (){

If (translate_object! = Null ){

Translate_object.rigidbody.transform.position.z + = 0.1;

}

}

Apply a rising force when the ball falls to the end.

# Pragma strict

Import System;

Var translate_object: Rigidbody;

Var li: int = 20;

Function FixedUpdate (){

If (translate_object! = Null ){

If (translate_object.rigidbody.transform.position.y <11 ){

Translate_object.rigidbody.AddForce (0, li, 0 );

}

}

}




1/(1*2) + 1/(2*3) + 1/(3*4) + ...... + 1/(19*20) = use a simple algorithm to write the process

1/1*2 + 1/2*3 + 1/3*4 + 1/4*5 + 1/5*6 ...... 1/19*20
= (1-1/2) + (1/2-1/3) + (1/3-1/4 )... + (1/18-1/19) + (1/19-1/20)
= 1-1/20
= 19/20

Simple Algorithm: 36-28 + 74-72

3.6 + 7.4-(2.8 + 7.2)
= 11-10
= 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.