2017-10-07 1 views
0

나는 우주 웹 사이트에서 발견 한 우주 사수 튜토리얼을 가지고 노는 중이며, 특정 지점에 도달하면 보스 적을 만들기 위해 노력하고 있습니다. 그러나 보스가 화면 중앙으로 이동하는 방법을 알 수는 없습니다. 나는 그것이 다른 적들을 위해 만든 발동기 스크립트와 관련이 있다고 생각합니다. 다른 적들은 화면의 맨 아래로 움직입니다. 화면에서 절반 정도 움직이는 보스 이동 스크립트를 어떻게 만들 수 있습니까?Unity- 개체를 이동시킨 다음 중지하려면 어떻게합니까?

public class Mover : MonoBehaviour { 
public float speed; 
private Rigidbody rb; 

void Start() 
{ 
    rb = GetComponent<Rigidbody>(); 
    rb.velocity = transform.forward * speed; 
} 
} 
+1

@Kenneth 것은, 당신이 답변을 받아 들일 수 너의 문제. – Programmer

+0

확인. 무리 감사 –

답변

0

는 다음과 같은 사용하여 객체를 중지 할 수 있습니다 Vector3.zero

rb.velocity =을; 그것을 테스트

당신이 뭔가를 할 수있는 다음과 같은 :

private void Update() { 
    if (Input.GetKeyDown(KeyCode.S)) { 
     rb.velocity = Vector3.zero; 
    } 
} 
1

나는 다음과 같은 강체의 MovePosition 기능을 사용 : 그들이 해결하는 경우

Vector3 screenCenter ; 

void Start() 
{ 
    rb = GetComponent<Rigidbody>(); 
    screenCenter = Camera.main.ViewportToWorldPoint(new Vector3(0.5,0.5, rb.position.y)); // If I remember right, thte game is a top-down game, right? 
} 

void FixedUpdate() 
{ 
    Vector3 direction = (screenCenter - rb.position); 
    float distance = Vector3.Distance(screenCenter, rb.position) ; 

    if(distance > Mathf.Epsilon) 
     rb.MovePosition(rb.position + speed * direction/distance * Time.deltaTime); 
} 
관련 문제