2013-09-25 1 views
0
using UnityEngine; 
using System.Collections; 

public class PlayerMovement : MonoBehaviour 
{ 
public float speed   = 3.0f; 
public float jumpSpeed   = 200.0f; 
public bool grounded   = true; 
public float time   = 4.0f;  



// Use this for initialization 
void Start() 
{ 

} 

// Update is called once per frame 
void FixedUpdate() 
{ 
    Vector3 x = Input.GetAxis("Horizontal")* transform.right * Time.deltaTime *  speed; 

    if (time <= 2) 
    { 
    if(Input.GetButtonDown("Jump")) 
     { 
       Jump(); 
     } 

    } 

    transform.Translate(x); 

    //Restrict Rotation upon jumping of player object 
    transform.rotation = Quaternion.LookRotation(Vector3.forward); 


} 
void Jump() 
    { 
     if (grounded == true) 
     { 
      rigidbody.AddForce(Vector3.up* jumpSpeed); 


      grounded = false; 
     } 

    } 
void OnCollisionEnter (Collision hit) 
{ 
    grounded = true; 
    // check message upon collition for functionality working of code. 
    Debug.Log ("I am colliding with something"); 
} 

} 

어디에서 그리고 어떤 유형의 코딩을 해야지?C# 유니티 플레이어 용 더블 점프 코딩 무브먼트 컨트롤

스프라이트 시트가있는 객체가 있으며 물리 엔진을 기반으로 운동과 일반 점프를 단합시켜야합니다. 하지만 나는 더 역동적 인 움직임을 원한다면 지상에 쉬었을 때 위치를 재설정하기 전에 점프 버튼을 몇 밀리 초 간격으로 누른 것처럼 특정 시간 프레임 사이에 접지되지 않으면 점프를 두 번만 수행하십시오.

답변

0

이 트릭을 수행해야합니다

private bool dblJump = true; 

void Jump() 
{ 
    if (grounded == true) 
    { 
     rigidbody.AddForce(Vector3.up* jumpSpeed); 

     grounded = false; 
    } 
    else if (!grounded && dblJump) 
    { 
     rigidbody.AddForce(Vector3.up* jumpSpeed); 

     dblJump = false; 
    } 

} 

void OnCollisionEnter (Collision hit) 
{ 
    grounded = true; 
    dblJump = true; 
    // check message upon collition for functionality working of code. 
    Debug.Log ("I am colliding with something"); 
} 
+0

u는이 코드를 잘하고 내가 그것을 잘 작동 테스트하지만 난 자유 낙하에 그것을 발견 플레이어가 여전히 내가 원하지 않는 dblJump 명령을 받아들입니다. 이에 따라 dblJump가 활성화 된 특정 범위의 가속도에서 자유 낙하와 같은 가속 범위를 지나면 dblJump 옵션이 비활성화되는 방식으로 작동합니다. –

+0

rigidbody.velocity (http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody-velocity.html)를 확인하고 시도하면 속도가 떨어지는 것을 나타낼 수 있습니다. – Chris

관련 문제