'2014/02/25'에 해당되는 글 12건

  1. 2014.02.25 플레이어 컨트롤 스크립트
  2. 2014.02.25 배경 시차 스크롤 카메라의 움직임에따라

플레이어 컨트롤 스크립트

|


Taunt -> 점수 획득시 호출 -> 플레이어 웃음 소리 랜덤으로 발생 -> 같은 웃음소리면 다시 호출해서 다른 웃음소리가 나올때까지 호출함(재귀호출)


Linecast-> 라인 캐스트를 사용해서 플레이어의 밑이 Ground인지 파악한다. -> 오브젝트의 레이어 이름이 Ground여야 됨..


groundCheck -> 빈 게임 오브젝트를 캐릭터 밑에 위치 시킴. 인스펙터창에서 모양을 지정해줄수있어서 어디 위치했는지 쉽게 알수 있음.


if(h * rigidbody2D.velocity.x < maxSpeed)

rigidbody2D.AddForce(Vector2.right * h * moveForce);

if(Mathf.Abs(rigidbody2D.velocity.x) > maxSpeed)

rigidbody2D.velocity = new Vector2(Mathf.Sign(rigidbody2D.velocity.x) * maxSpeed, rigidbody2D.velocity.y);


플레이어의 속도가 최대속도보다 아래면 힘을주고 아니면 속도를 최대속도로 제한해준다.


if(h > 0 && !facingRight)
// ... flip the player.
Flip();
// Otherwise if the input is moving the player left and the player is facing right...
else if(h < 0 && facingRight)
// ... flip the player.
Flip();

플레이어의 모양을 보고 왼쪽이면 왼쪽을 바라보게 오른쪽이면 오른쪽으로 바라보게 한다.


if(jump)
{
// Set the Jump animator trigger parameter.
anim.SetTrigger("Jump");

// Play a random jump audio clip.
int i = Random.Range(0, jumpClips.Length);
AudioSource.PlayClipAtPoint(jumpClips[i], transform.position);

// Add a vertical force to the player.
rigidbody2D.AddForce(new Vector2(0f, jumpForce));

// Make sure the player can't jump again until the jump conditions from Update are satisfied.
jump = false;
}

점프 중이면. 랜덤으로 점프 사운드를 재생하고 위쪽으로 힘을 가한다(AddForce)


-> 모든 물리관련 동작은 FixedUpdate()에서 실행한다.


솔직히 아직도 재귀함수에 대한 이해가 부족한거 같음
된다는건 알고있지만 뭔가 이상하다..





Trackback 0 And Comment 0

배경 시차 스크롤 카메라의 움직임에따라

|


배경 시차 스크롤 카메라의 움직임에 따라서 배경의 움직임이  달라짐.

Background 빈 오브젝트에 각각의 값들을 집어넣으면 그 값들은 각각의 속도가 다름..

뭔가 파악하기 어려운 소스지만.. 일단 대강은 이해가 감.




parallax.unitypackage


카메라를 이동가능하게 만듬..



parallaxScale -> 시차 스크롤링 속도 (카메라의 움직임에 따라 값이 클수록 더 빨리 배경이 움직임)


parallaxReductionFactor -> 각 레이어 별 시차 스크롤 속도 차이 값이 클수록 각 레이어별로 속도 차이가 크다.


smothing -> Lerp 함수에 입력된 값


Trackback 0 And Comment 0
prev | 1 | 2 | next