중력 감응 조종(unity 아이폰)
                                            
 1666 단어  iPhone
                    
 :speed
 public var simulateAccelerometer:boolean = false;
var speed = 10.0;
function Update () {
	var dir : Vector3 = Vector3.zero;
	if (simulateAccelerometer)
	{
		dir.x = Input.GetAxis("Horizontal");
		dir.y = Input.GetAxis("Vertical");
	}
	else
	{
		dir.x = Input.acceleration.x;
		dir.y = Input.acceleration.y;
	
		// clamp acceleration vector to unit sphere
		if (dir.sqrMagnitude > 1)
			dir.Normalize();
		// Make it move 10 meters per second instead of 10 meters per frame...
	}
	dir *= Time.deltaTime;
	// Move object
	transform.Translate (dir * speed);
}
  
스피드를 힘으로 바꿀 수도 있어요. :Force
  public var force:float = 1.0;
public var simulateAccelerometer:boolean = false;
function FixedUpdate () {
	var dir : Vector3 = Vector3.zero;
	if (simulateAccelerometer)
	{
		// using joystick input instead of iPhone accelerometer
		dir.x = Input.GetAxis("Horizontal");
		dir.y = Input.GetAxis("Vertical");
	}
	else
	{
		// we assume that device is held parallel to the ground
		// and Home button is in the right hand
		
		// remap device acceleration axis to game coordinates
		// 1) XY plane of the device is mapped onto XZ plane
		// 2) rotated 90 degrees around Y axis
		dir.x = Input.acceleration.y;
		dir.y = Input.acceleration.x;
		
		// clamp acceleration vector to unit sphere
		if (dir.sqrMagnitude > 1)
			dir.Normalize();
	}
	
	rigidbody.AddForce(dir * force);
}
  
개인적인 감각 방안은 조종하기만 하면 비교적 유연하고 반응이 민감하다.방안2는 조종하기 시작하면 관성을 가지고 완충이 뚜렷하다.이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
IOS Application core architectureA new IOS application program is mainly composed of the following files: If the app delegate class is nil, UIKit will as...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.