GMU:Techniken des Virtuellen/Miaomiao Ning: Difference between revisions

From Medien Wiki
Line 48: Line 48:
[https://www.youtube.com/watch?v=RbPW2_f4YVk| Test video:Use pulse sensor in unity3D ]<br>
[https://www.youtube.com/watch?v=RbPW2_f4YVk| Test video:Use pulse sensor in unity3D ]<br>
[[File:connect pulse sensor with Unity.png|left|250px|]]
[[File:connect pulse sensor with Unity.png|left|250px|]]
———Unity script——————————————————————<br>
———Unity script——————————————————————<br>
using System.Collections;<br>
using System.Collections;<br>
Line 64: Line 65:
———Unity script——————————————————————<br>
———Unity script——————————————————————<br>


3.realize the rotation and wave of monuments<br>
Since the pulse sensor is not so sensitive and have delay in any way, I simulate the heart beat
with sine trigonometric function.<br>
———Unity script ————————————————————————————————————————————<br>
using System.Collections;<br>
using System.Collections.Generic;<br>
using UnityEngine;<br>
public class simulatepulse : MonoBehaviour {<br>
Vector3 tempos;<br>
float amplitudeY = 0.5f;<br>
float omegaY = 2.0f;<br>
float index;<br>
void Start () {<br>
float a = Random.value; <br>
amplitudeY = amplitudeY + a;<br>
}<br>
void Update () {<br>
float x0 = transform.position.x;<br>
float z0 = transform.position.z;<br>
float camerax = Camera.main.transform.position.x;<br>
float cameraz = Camera.main.transform.position.z;<br>
float dx = camerax - x0;<br>
float dz = cameraz - z0;<br>
index += Time.deltaTime;<br>
float y = Mathf.Abs (amplitudeY*Mathf.Sin (amplitudeY+(omegaY*index)));<br>
if((Mathf.Abs(dx) < 2) & (Mathf.Abs(dz) < 2) ){<br>
transform.localScale= new Vector3(1,1,y);<br>
}<br>
———Unity script ————————————————————————————————————————————<br>


<br clear="all" />
<br clear="all" />