내용으로 건너뛰기
GINS WIKI 긴스 위키
사용자 도구
로그인
사이트 도구
검색
도구
문서 보기
이전 판
역링크
최근 바뀜
미디어 관리자
사이트맵
로그인
>
최근 바뀜
미디어 관리자
사이트맵
현재 위치:
긴스위키 GINS wiki
»
개발 언어
»
2d-game-physics
»
Velocity
추적:
language:2d-game-physics:2d-game-physics-101
이 문서는 읽기 전용입니다. 원본을 볼 수는 있지만 바꿀 수는 없습니다. 문제가 있다고 생각하면 관리자에게 문의하세요.
출처 : [[http://www.rodedev.com/tutorials/gamephysics/game_physics.swf]] ====== Velocity ====== <code javascript> // set initial angle and speed var angle = 30; var speed = 20; // calcuate x, y scales (this will give the x/y equivalent of the angle) var scale_x = cos(angle); // the x scale is the sin of the angle var scale_y = sin(angle); // the y scale is the sin of the angle var velocity_x = (speed * scale_x); // speed times scal_x is our x velocity var velocity_y = (speed * scale_y); // speed times scale_y is our y velocity // each frame call game loop to set object's position(move it along the predefined angle) function GameLoop() { movingObject.x = movingObject.x + velocity_x; movingObject.y = movingObject.y + velocity_y; }//end game loop </code> ======Acceleration====== <code javascript> // set initial angle and speed, acceleration var angle = 30; movingObject.speed = 20; movingObject.acceleration = 2; // calcuate x, y scales (this will give the x/y equivalent of the angle) var scale_x = cos(angle); // the x scale is the sin of the angle var scale_y = sin(angle); // the y scale is the sin of the angle // each frame call game loop to set object's position(move it along the predefined angle) function GameLoop() { // continously add acceleration to speed movingObject.speed = movingObject.speed + movingObject.acceleration; // speed times scale_x, scale_y is our x/y velocity movingObject.velocity_x = (movingObject.speed * scale_x); movingObject.velocity_y = (movingObject.speed * scale_y); movingObject.x = movingObject.x + movingObject.velocity_x; movingObject.y = movingObject.y + movingObject.velocity_y; }//end game loop </code> ======Gravity====== <code javascript> // set gravity constant var gravity = 3; var moving = true; // each frame call game loop to set object's position function GameLoop() { if( moving == true ) { velocity_y = velocity_y - gravity; // if object has not hit the ground add y velocity(may be a negative velocity) if( movingObject.y - velocity_y > ground.y ) { movingObject.y = movingObject.y + velocity_y; } movingObject.x = movingObject.x + velocity_x; } } </code> ======Throwing/Passing====== 오브젝트를 던지거나 패스하는 경우, * x 축 속도 : 이동할 거리 / 희망 도착 시간 * x velocity is equal to the distance an object needs to travel to reach its destination divided by the amout of time you want the object to take to reach its destination. * x velocity = distance / time \\ distance = x velocity * time \\ time = distance / x velocity * y 축은 중력에 대해서 고려해줘야 한다. * y velocity = time * gravity * 0.5f 코드 예제 <code javascript> function GameLoop() { if( thrown == true && moving == false ) { moving = true; // get distance between two guys var distance = guy2.x - guy1.x; // claculate x and y velocities velocity_y = time * gravity * 0.5; velocity_x = distance / time; } // .... if( moving == true ) { ball.x = ball.x + velocity_x; ball.y = ball.y + velocity_y; velocity_y = velocity_y - gravity; } } </code> ======Distance & Timing====== {{:language:2d-game-physics:2d-physics-101-1.jpg|}} ======Frame Rate & Deviance====== {{:language:2d-game-physics:2d-physics-101-2.jpg|}}
language/2d-game-physics/2d-game-physics-101.txt
· 마지막으로 수정됨: 2024/04/23 22:44 저자
127.0.0.1
문서 도구
문서 보기
이전 판
역링크
맨 위로