Unity-7: physics
edit- projectsetting - physics
- gravity - 중력
- bounce - 튀기는 정도
- sleep - 해당 값만큼 의 시간 동안 움직임이 없다면 안움직이는 물체로 인식
rigid body
- gameobject를 물리적 연산이 발동되도록 하기 위해서는 Rigidbody컴퍼넌트를 add해야한다
오른쪽 add component 에서 rigid body 입력 - 부딪히는 두개의 물체가 모드 rigidbody가 있어야함
- use gravity: 중력을 적용할지 안할지
- mass : 물체 자체의 기본 무게
- drag: 공기저항
- angular drag : 회전 저항
-
Is Kinematic : 본인은 물리적연산을 하지 않지만, 다른물체가 나와 충돌했을때 그 물체를 물리적연산을 주는것
- constraints (제약)
- Freezen position: 충돌이 일어났을때 좌표축 x, y, z축을 고정시키는것
- Freezen rotation: 충돌이 일어났을때 회전축 x, y, z축을 고정시키는것
collider
- 충돌의 감지
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GravityControl : MonoBehaviour
{
Rigidbody _rg;
public float _gravityScale = 1;
float _gravityNormal = 9.8f;
// Start is called before the first frame update
void Start()
{
_rg = GetComponent<Rigidbody>();
_rg.mass = 100;
}
// Update is called once per frame
void Update()
{
float gx = Input.GetAxis("Horizontal");
float gy = Input.GetAxis("Vertical");
Vector3 g = new Vector3(gx, -1, gy);
g.Normalize();
Physics.gravity = g * _gravityNormal * _gravityScale;
//Debug.Log(physics.gravity);
}
void OnCollisionEnter(Collision other)
{
Debug.Log(other.gameObject + "와 충돌했다.");
}
void OnCollisionExit(Collision other)
{
Debug.Log(other.gameObject + "와 떨어졌다.");
}
void OnCollisionStay(Collision other)
{
Debug.Log(other.gameObject + "와 충돌중이다.");
}
}
- onCollisionEnter : 최초 충돌했을때 1번 발생
- onCollisionExit : 충돌하고나서 떨어졌을때 1번 발생
- OnCollisionStay: 충돌하고 떨어지지 않는 동안에(접총중에) 계속 발생
Is Trigger
- Is Trigger 를 체크하면, trigger Check 상태로 변함
- 물리적영향 없이 충돌에 대한 감지만 체크하는것!!
- Enter, Exit, Stay
- Trigger 체크를 통해 게임상에서 범위공격에 대한 데미지 체크…
void OnTriggerEnter(Collider other)
{
Debug.Log(other.gameObject + "와 충돌을 체크했다");
}
physics material
- 물체 표면에 물리적인 운동을 주고 싶을 때
- project → +클릭 → physics material 클릭
- bounce: 튀기는 정도
- friction: 마찰력
- static friction: 반작용(최초에 움직이는게 힘든것들)
댓글남기기