2014-02-11 3 views
1

내가 현재 가지고플라잉 문자

#pragma strict 

var cMotor: CharacterMotor; // reference to the CharacterMotor script 

function Start(){ // get the CharacterMotor script at Start: 
cMotor = GetComponent(CharacterMotor); 
} 

function Update(){ // move player upwards while F is pressed 
if (Input.GetKey("f")){ 
cMotor.SetVelocity(Vector3.up*10.5);} 
else if (Input.GetKey("up")){ 
cMotor.SetVelocity(Vector3.forward*10.5); 
} 
else if (Input.GetKey("left")){ 
cMotor.SetVelocity(Vector3.left*10.5); 
} 
else if (Input.GetKey("down")){ 
cMotor.SetVelocity(Vector3.back*10.5); 
} 
else if (Input.GetKey("right")){ 
cMotor.SetVelocity(Vector3.right*10.5); 
} 
else if (Input.GetKey("g")){ 
cMotor.SetVelocity(Vector3.down*10.5); 
} 
} 

// This do-nothing function is included just to avoid error messages 
// because SetVelocity tries to call it 

function OnExternalVelocity(){ 
} 

그러나 나는 그들이 떨어지지 않도록 공중에 문자를 동결 할 수 있도록하려면하지만 난 경우 다음 스크립트와 함께 공중에 비행 내 캐릭터 maxFallSpeed를 0으로 설정하면 캐릭터 토큰을 다시 만들 수 없습니다. 어떤 아이디어?

+0

저는 이것이 자바 스크립트라고 생각합니다. 질문에이 태그를 추가 할 가치가 있습니다. –

답변

0

CharacterMotor는 기본 unity3d 스크립트가 아니기 때문에 익숙하지 않지만 직접 작성했거나 자습서에서 가져온 것입니다. 그 점을 염두에두고, 아무 키도 누르지 않으면 강체를 사용하지 않도록 설정하는 것이 좋습니다.

function Update() { 
    if(!Input.anyKey) { 
     Rigidbody.mass = 0.0f; 
     Rigidbody.drag = 50; 
    } else { 
     Rigidbody.mass = 1.0f; // or the stored variabled of the initial mass 
     Rigidbody.drag = 0.7f; 
    } 
} 

그 원시 방법이지만 작동합니다. 문제는 캐릭터 모터가 charactercontroller.move 또는 simplemove를 사용하여 캐릭터를 끌어 내리는 것입니다.

문자 모터에 부울을 추가하고 중력 검사를 수행 할 때 어떤 키가 눌러지면 true를 반환하는 Input.anyKey를 사용하여 부울을 비활성화하고 아무 키도 누르지 않으면 false를 반환합니다.

편집 : 코드는 아래 주석에 정의 된대로 변경됩니다.

+0

리지드 바디에는 'enabled'필드가 없습니다. 그것은 'Component'이지만, MonoBehavior가 아닙니다. 'rigidBody.Sleep()'와'rigidBody.WakeUp()'를 대신 호출해야합니다. –

+0

죄송합니다. 내 실수는 사실입니다. 실제로 질량을 변경할 수도 있습니다. 0으로 설정하면 플레이어가 대기 상태가되지만 다른 환경 변화는 계속 처리 할 수 ​​있습니다. –

+0

그게 중력을 멈추지 않을거야,하지만 그것을 멈추지 않을 것입니다 ... –

1

시도해보십시오. 기본 "w, s, a, d"를 사용하여 이동하고 "f, g"는 위아래로 사용하십시오.

#pragma strict 

var cMotor: CharacterMotor; // reference to the CharacterMotor script 

function Start(){ // get the CharacterMotor script at Start: 
    cMotor = GetComponent(CharacterMotor); 
} 

function Update(){ // move player upwards while F is pressed 

if (Input.GetKey("f")){ 
    cMotor.SetVelocity(Vector3.up*6); 
}else if(Input.GetKeyUp("f")){ 
    cMotor.SetVelocity(Vector3.up*0); 
} 


if(Input.GetKey("g")){ 
    cMotor.SetVelocity(Vector3.down*6); 
}else if(Input.GetKeyUp("g")) { 
    cMotor.SetVelocity(Vector3.down*0); 
} 
} 

// This do-nothing function is included just to avoid error messages 
// because SetVelocity tries to call it 

function OnExternalVelocity(){ 
}