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