'분류 전체보기'에 해당되는 글 162건

  1. 2019.10.04 04. 10/3 softBody effect
  2. 2019.10.02 d
  3. 2019.10.02 03. 10/2 physics & leapmotion SDK
  4. 2019.10.02 02. 기술 기획


젤리 효과를 넣을 gameObject에 적용할 스크립트

Collision chk를 하기 때문에 rigidBody 필요함.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class jellyFier : MonoBehaviour
{
    public float bounceSpeed;
    public float fallForce;
    public float stiffness;
 
    private MeshFilter meshFilter;
    private Mesh mesh;
 
    jellyVertex[] jellyVertices;
    Vector3[] currentMeshVertices;
 
    private void Start()
    {
        meshFilter = GetComponent<MeshFilter>();
        mesh = meshFilter.mesh;
 
        GetVertices();
    }
 
    private void GetVertices()
    {
        jellyVertices = new jellyVertex[mesh.vertices.Length];
        currentMeshVertices = new Vector3[mesh.vertices.Length];
        for(int i=0; i< mesh.vertices.Length; i++)
        {
            jellyVertices[i] = new jellyVertex(i, mesh.vertices[i], mesh.vertices[i], Vector3.zero);
            currentMeshVertices[i] = mesh.vertices[i];
        }
    }
 
    private void Update()
    {
        UpdateVertices();
    }
 
    private void UpdateVertices()
    {
        for(int i=0; i<jellyVertices.Length; i++)
        {
            jellyVertices[i].UpdateVelocity(bounceSpeed);
            jellyVertices[i].Settle(stiffness);
 
            jellyVertices[i].currentVertexPosition += jellyVertices[i].currentVelocity * Time.deltaTime;
            currentMeshVertices[i] = jellyVertices[i].currentVertexPosition;
        }
 
        mesh.vertices = currentMeshVertices;
        mesh.RecalculateBounds();
        mesh.RecalculateNormals();
        mesh.RecalculateTangents();
    }
 
    public void OnCollisionEnter(Collision col)
    {
        ContactPoint[] collisionPoints = col.contacts;
        for(int i = 0; i< collisionPoints.Length; i++)
        {
            Vector3 inputPoint = collisionPoints[i].point + (collisionPoints[i].point * .1f);
            ApplyPressureToPoint(inputPoint, fallForce);
        }
    }
 
    public void ApplyPressureToPoint(Vector3 _point, float _pressure)
    {
        for(int i=0; i< jellyVertices.Length; i++)
        {
            jellyVertices[i].ApplyPressureToVertex(transform, _point, _pressure);
        }
    }
}
 
cs


추가적으로 필요한 스크립트

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class jellyVertex : MonoBehaviour
{
    public int verticeIndex;
    public Vector3 initialVertexPosition;
    public Vector3 currentVertexPosition;
 
    public Vector3 currentVelocity;
 
    public jellyVertex(int _verticeIndex, Vector3 _initialVertexPosition, Vector3 _currentVertexPosition, Vector3 _currentVelocity)
    {
        verticeIndex = _verticeIndex;
        initialVertexPosition = _initialVertexPosition;
        currentVertexPosition = _currentVertexPosition;
        currentVelocity = _currentVelocity;
    }
 
    public Vector3 GetCurrentDisplacement()
    {
        return currentVertexPosition - initialVertexPosition;
    }
 
    public void UpdateVelocity(float _bounceSpeed)
    {
        currentVelocity = currentVelocity - GetCurrentDisplacement() * _bounceSpeed * Time.deltaTime;
    }
 
    public void Settle(float _stiffness)
    {
        currentVelocity *= 1f - _stiffness * Time.deltaTime;
    }
 
    public void ApplyPressureToVertex(Transform _transform, Vector3 _position, float _pressure)
    {
        Vector3 distanceVerticePoint = currentVertexPosition - _transform.InverseTransformPoint(_position);
        float adaptedPressure = _pressure / (1f + distanceVerticePoint.sqrMagnitude);
        float velocity = adaptedPressure * Time.deltaTime;
        currentVelocity += distanceVerticePoint.normalized * velocity;
    }
}
 
cs


튜토리얼

https://www.youtube.com/watch?v=UxLJ6XewTVs&t=31s

'Project > TouchMe' 카테고리의 다른 글

10/6 procedural grid, physics and soft body(nvidia flux)  (0) 2019.10.08
10/5 procedural Mesh  (0) 2019.10.05
03. 10/2 physics & leapmotion SDK  (0) 2019.10.02
02. 기술 기획  (0) 2019.10.02
01. 프로젝트 기획  (0) 2019.10.02
Posted by 도이(doi)
,

d

카테고리 없음 2019. 10. 2. 18:15

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GetVertX : MonoBehaviour
{
public GameObject someObject;
public Vector3 thePosition;

//private LookAt la;

void Start()
{
//Mesh mesh = GetComponent<MeshFilter>().sharedMesh;
//Mesh mesh2 = Instantiate(mesh);
//GetComponent<MeshFilter>().sharedMesh = mesh2;
MeshGenerator();
}

private void MeshGenerator()
{
Mesh mesh = GetComponent<MeshFilter>().mesh;
Vector3[] vertices = mesh.vertices;

int v = 0;
Debug.Log(vertices.Length);

//빈도
//for (int i = 0; i < vertices.Length;i++)
//{
// if (i % 5 == 0)
// {
// thePosition = transform.TransformPoint(vertices[i]);
// //lookat
// //Quaternion rot = Quaternion.LookRotation(Vector3.zero - thePosition);
// GameObject quad = Instantiate(someObject, thePosition, someObject.transform.rotation);
// }

//}
while (v < vertices.Length)
{
thePosition = transform.TransformPoint(vertices[v]);
//lookat
//Quaternion rot = Quaternion.LookRotation(Vector3.zero - thePosition);
GameObject quad = Instantiate(someObject, thePosition, someObject.transform.rotation);
//quad.AddComponent<LookAt>();
v++;
}
}

}

Posted by 도이(doi)
,

marpi stuido

leapmotionSDK


unity Physics 튜토리얼(한글자막)

1. Colliders
유니티에는 mesh 와 collider가 있다. mesh는 우리 눈에 보이는 덩어리이고, collider는 물리적 충돌 영역을 표시한다.


2. Colliders asTriggers
Collider에 isTrigger을 체크하게 되면, 다른 gameObject와 충돌하지 않는다. 주로, 충돌 체크를 하기 위해서 mesh없이 collider만 놓고 쓴다.


3. RigidBodies
게임 속에서 물리력을 받도록 설정하는 것이다. 
중력을 설정할 수 있다.
세부적인 중력 설정은, edit > projectSetting > Physics에서 설정가능.
is Kinematic을 체크하면, 다른 gameObject의 물리적 영향을 받지 않고, 고정되어있는다. 주로, 공 튀기기 게임에서 map이라고 생각하면 된다. 
(공을 튕기지만, 움직이지 않음.)


4. Adding Physics Froces and Torque
position / rotation에 추가적인 힘을 주는 것이다. (스크립트로 제어)


6. Physics Materials
고무가 플라스틱보다 더 탄성이 있는 것 처럼 재질의 물리력을 세팅해준다. collider component 창에 추가한다. 


7. Physics Joints
fixed Joint, Spring Joint, Hinge Joint
damper: 완충 작용
break force/ break Torque: 끊어지게 하는 최소한의 힘 설정
(끊어지지 않기 위해서는 infinity로 설정.)


8. Detecting Collisions with OnCollisionEnter
부딪혔는지 체크함. (스크립트)


9. Raycasting
레이저 빔을 쏘아서 충돌 체크함. 


hinge joint를 이용한 x, z축 움직임 체크

'Project > TouchMe' 카테고리의 다른 글

10/6 procedural grid, physics and soft body(nvidia flux)  (0) 2019.10.08
10/5 procedural Mesh  (0) 2019.10.05
04. 10/3 softBody effect  (0) 2019.10.04
02. 기술 기획  (0) 2019.10.02
01. 프로젝트 기획  (0) 2019.10.02
Posted by 도이(doi)
,

02. 기술 기획

Project/TouchMe 2019. 10. 2. 15:17

1차

physics 연구 (collider, rigidbody, joint)

leap motion 연구


2차

shader 연구


3차 

shader graph 연구

'Project > TouchMe' 카테고리의 다른 글

10/6 procedural grid, physics and soft body(nvidia flux)  (0) 2019.10.08
10/5 procedural Mesh  (0) 2019.10.05
04. 10/3 softBody effect  (0) 2019.10.04
03. 10/2 physics & leapmotion SDK  (0) 2019.10.02
01. 프로젝트 기획  (0) 2019.10.02
Posted by 도이(doi)
,