- 最后登录
- 2017-4-1
- 注册时间
- 2011-7-26
- 阅读权限
- 90
- 积分
- 24690
- 纳金币
- 24658
- 精华
- 6
|
方案二:Force
public var force:float = 1.0;
02 public var simulateAccelerometer:boolean = false;
03
04 function FixedUpdate () {
05 var dir : Vector3 = Vector3.zero;
06
07 if (simulateAccelerometer)
08 {
09 // using joystick input instead of iPhone accelerometer
10 dir.x = Input.GetAxis("Horizontal");
11 dir.y = Input.GetAxis("Vertical");
12 }
13 else
14 {
15 // we assume that device is held parallel to the ground
16 // and Home button is in the right hand
17
18 // remap device acceleration axis to game coordinates
19 // 1) XY plane of the device is mapped onto XZ plane
20 // 2) rotated 90 degrees around Y axis
21 dir.x = Input.acceleration.y;
22 dir.y = Input.acceleration.x;
24 // clamp acceleration vector to unit sphere
25 if (dir.sqrMagnitude > 1)
26 dir.Normalize();
27 }
28
29 rigidbody.AddForce(dir * force);
30 }
转自:http://www.cnblogs.com/lm3515/archive/2010/09/24/1833957.html
|
|