http://cafe.naver.com/xgdn/5043
'유니티3D > 예제' 카테고리의 다른 글
메카님방식 (0) | 2013.08.12 |
---|---|
BulletCtrl.cs (0) | 2013.08.07 |
PlayerCtrl (0) | 2013.08.06 |
Bullet (0) | 2013.08.06 |
MyGizmo.cs (0) | 2013.08.06 |
http://cafe.naver.com/xgdn/5043
메카님방식 (0) | 2013.08.12 |
---|---|
BulletCtrl.cs (0) | 2013.08.07 |
PlayerCtrl (0) | 2013.08.06 |
Bullet (0) | 2013.08.06 |
MyGizmo.cs (0) | 2013.08.06 |
Rigidbody.AddForce(Vector3 , Mode) 함수는 리지드 바디에 힘을 줘 움직이기 위한 함수다.
첫번째 인수에 힘의 방향과 크기를 넣게 되고
두번째 인수에는 힘을 주는 모드를 지정해준다.
비록 같은 힘의 크기와 방향을 줬어도 모드에 따라 다른 움직임이 나오게 되는데
그 모드에 대해서 한번 정리를 해봤다.
ForceMode.Force
- 역학적인 개념의 힘을 리지드 바디에 주는 모드다.
짧은 시간에 발생하는 운동량 변화의 크기를 나타내며
주로 바람이나 자기력처럼 연속적으로 주어지는 힘을 나타내는 데 이용 된다.
ForceMode.Impulse
- 충격량을 리지드바디에 주는 모드로 충격량이랑 힘의 크기와 주는 시간을 곱한 수치다.
주로 타격이나 폭팔처럼 순간적으로 힘을 나타내는 데 이용된다.
ForceMode.Acceleration
- 리지드바디가 갖는 질량을 무시하고 직접적으로 가속량을 주는 모드다.
앞의 두 모드의 경우 질량에 따라 움직임이 달라지지만 이 모드의 경우 질량에 상관 없이 일정한 가속을 만들어 낸다.
주로 지구의 중력 표현에 쓰인다.
ForceMode.VelocityChange
- 리지드바디가 가진 질량을 무시하고 직접적으로 속도의 변화를 주는 모드다.
앞서 말한 Acceleration은 시간이 흘러가면서 변화를 일으키는 데 비해 이 모드는 순간적으로 지정한 속도로 변화를 일으킨다.
[출처] Rigidbody.AddForce() 힘 모드 종류에 대해서|작성자 토이박스 [출처] Rigidbody.AddForce() 힘 모드 종류에 대해서|작성자 토이박스
UNITY3D 자주쓰는 스크립트_3 (0) | 2013.09.29 |
---|---|
UNITY3D 자주쓰는 스크립트_2 (0) | 2013.09.27 |
UNITY3D 자주쓰는 스크립트_1 (0) | 2013.09.27 |
C# 스크립트 함수 _2 (0) | 2013.07.21 |
C# 스크립트 심화_1 (0) | 2013.07.21 |
using UnityEngine;
using System.Collections;
public class PlayCtrl : MonoBehaviour {
[System.Serializable] //it makes that i can use c#
public class Anim
{
public AnimationClip Idle;
public AnimationClip runForward;
public AnimationClip runBackward;
public AnimationClip runRight;
public AnimationClip runLeft;
}
public Anim anim;
public Animation aniBody;
public float Speed = 10.0f;
public GameObject BulletPrefab;
public Transform firepos; //i can Input other objects.
// Use this for initialization
void Start ()
{
aniBody.clip = anim.Idle;
aniBody.Play();
}
// Update is called once per frame
void Update () {
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
transform.Translate(Vector3.right * h * Speed * Time.deltaTime);
transform.Translate(Vector3.forward * v * Speed * Time.smoothDeltaTime); // i need to cheak!
if(h > 0.1f)
{
aniBody.CrossFade(anim.runRight.name,0.3f);
}
else if(h < -0.1f)
{
aniBody.CrossFade(anim.runLeft.name,0.3f);
}
else if(v > 0.1f)
{
aniBody.CrossFade(anim.runForward.name,0.3f);
}
else if(v < -0.1f)
{
aniBody.CrossFade(anim.runBackward.name,0.3f);
}
else{
aniBody.CrossFade(anim.Idle.name,0.3f);
}
// if(Input.GetMouseButtonDown(0)) --> when I click Left mouse
if(Input.GetMouseButtonDown(0))
{
StartCoroutine("Fire"); //method name is Fire~ ~!! it's just name.
//multi Thread
}
}
IEnumerator Fire() //if return type is IEnumerator.. this method is multi thread..
{
GameObject newBullet = (GameObject)Instantiate(BulletPrefab,firepos.position,Quaternion.identity);
//Quaternion.Euler(x,y,z); rotation...
Destroy(newBullet, 3.0f); //after i fired bullet..
yield return null;
}
}
BulletCtrl.cs (0) | 2013.08.07 |
---|---|
miniMap (0) | 2013.08.07 |
Bullet (0) | 2013.08.06 |
MyGizmo.cs (0) | 2013.08.06 |
Spark.cs (0) | 2013.08.06 |
using UnityEngine;
using System.Collections;
public class Bullet : MonoBehaviour {
// Use this for initialization
void Start () {
rigidbody.AddForce(Vector3.forward * 1000.0f);
}
}
miniMap (0) | 2013.08.07 |
---|---|
PlayerCtrl (0) | 2013.08.06 |
MyGizmo.cs (0) | 2013.08.06 |
Spark.cs (0) | 2013.08.06 |
bulletCtrl (0) | 2013.07.25 |