2.現在有球有線,我們想要讓他可以一直生成,所以利用instantiate()這個函式,不斷呼叫prefab,這樣可以產生出很多球跟線,模擬棉花糖機噴絲的感覺。
2019年6月29日 星期六
2019年6月24日 星期一
2019年6月16日 星期日
2019年6月4日 星期二
2019年5月21日 星期二
逸臻的筆記Week14-期末作品進度#5
-期末作品進度#5-
分開碰撞物件 ( 把一個物件套一個程式 )
球1程式碼:
using System.Collections;using System.Collections.Generic;
using UnityEngine;
public class bom : MonoBehaviour
{
GameObject realBoard=null;
public GameObject board;
public GameObject BAT; //BAT手把
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
float x=0;
void Update()
{
}
void OnTriggerEnter(Collider collision)
{
print("collision");
if(realBoard==null) realBoard = Instantiate(board); //碰撞後秀出文字板
}
}
球2程式碼:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bom2 : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter(Collider collision)
{
print("collision22222");
}
}
using System.Collections.Generic;
using UnityEngine;
public class bom2 : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter(Collider collision)
{
print("collision22222");
}
}
week14 Jie
旋轉物件(四)
完成後跟老師討論,發現按壓旋轉的方式非常不方便,於是更改為滑動方式並加入過關條件
1.更改程式碼如下
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
[RequireComponent(typeof(SteamVR_TrackedObject))]
public class ControllerTest : MonoBehaviour {
SteamVR_TrackedObject trackedObj;
SteamVR_Controller.Device device,deviceLeft,deviceRight;
public GameObject obj;
float a=0.0f,b=0.0f,c=0.0f;
Vector2 rotat=new Vector2(0.0f,0.0f);
public static bool over=false;
void Start () {
trackedObj=GetComponent<SteamVR_TrackedObject>();
a=obj.transform.rotation.x;
b=obj.transform.rotation.y;
c=obj.transform.rotation.z;
}
// Update is called once per frame
Vector2 tp2;
bool bTouched=false;
void Update () {
device = SteamVR_Controller.Input ((int)trackedObj.index);
var leftHand = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Leftmost);
deviceLeft = SteamVR_Controller.Input (leftHand);
var rightHand = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost);
deviceRight = SteamVR_Controller.Input (rightHand);
Vector2 tp=Vector2.zero,tp1=Vector2.zero;
if (device.GetTouch (SteamVR_Controller.ButtonMask.Touchpad)){
//由原先的GetPress更改為GetTouch
tp2 = tp1;//備份第一次碰到的位置
tp1 = device.GetAxis ();//備份完後再讀取Touchpad碰到的位置
if(bTouched){
rotat=tp1-tp2;
//print("tp1:"+tp1+"\n");
//print("tp2:"+tp2);
//print("diff:"+ (tp1-tp2));
///....
float angle=Vector2.Angle (new Vector2 (1, 0), rotat);
if (angle > 45 && angle < 135) {
if (rotat.y > 0){
a+=3.0f;
if(a>180.0f)
a%=180.0f;
}
else{
a-=3.0f;
if(a<-180.0f)
a%=180.0f;
}
}
else {
if (rotat.x>0){
b+=3.0f;
if(b>180.0f)
b%=180.0f;
}
else{
b-=3.0f;
if(b<-180.0f)
b%=180.0f;
}
}
}
bTouched=true;
}
else
bTouched=false;
obj.transform.rotation = Quaternion.Euler (new Vector3 (a, b, c));
if((a<=-5.0f && a>=-25.0f) && (b<=80.0f && b>=60.0f)){
//若物件達到指定角度
over=true;
SceneManager.LoadScene ("start_menu");
}
}
}
2.過關條件判斷
因為我們程式的寫法是一直累加或減角度,導致最後數值會大於或小於360度,所以在做條件判斷時需將數值除以180取餘數,以取得正確的數值
if (angle > 45 && angle < 135) {
if (rotat.y > 0){
a+=3.0f;
if(a>180.0f)
a%=180.0f;
}
else{
a-=3.0f;
if(a<-180.0f)
a%=180.0f;
}
}
else {
if (rotat.x>0){
b+=3.0f;
if(b>180.0f)
b%=180.0f;
}
else{
b-=3.0f;
if(b<-180.0f)
b%=180.0f;
}
}
完成後跟老師討論,發現按壓旋轉的方式非常不方便,於是更改為滑動方式並加入過關條件
1.更改程式碼如下
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
[RequireComponent(typeof(SteamVR_TrackedObject))]
public class ControllerTest : MonoBehaviour {
SteamVR_TrackedObject trackedObj;
SteamVR_Controller.Device device,deviceLeft,deviceRight;
public GameObject obj;
float a=0.0f,b=0.0f,c=0.0f;
Vector2 rotat=new Vector2(0.0f,0.0f);
public static bool over=false;
void Start () {
trackedObj=GetComponent<SteamVR_TrackedObject>();
a=obj.transform.rotation.x;
b=obj.transform.rotation.y;
c=obj.transform.rotation.z;
}
// Update is called once per frame
Vector2 tp2;
bool bTouched=false;
void Update () {
device = SteamVR_Controller.Input ((int)trackedObj.index);
var leftHand = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Leftmost);
deviceLeft = SteamVR_Controller.Input (leftHand);
var rightHand = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost);
deviceRight = SteamVR_Controller.Input (rightHand);
Vector2 tp=Vector2.zero,tp1=Vector2.zero;
if (device.GetTouch (SteamVR_Controller.ButtonMask.Touchpad)){
//由原先的GetPress更改為GetTouch
tp2 = tp1;//備份第一次碰到的位置
tp1 = device.GetAxis ();//備份完後再讀取Touchpad碰到的位置
if(bTouched){
rotat=tp1-tp2;
//print("tp1:"+tp1+"\n");
//print("tp2:"+tp2);
//print("diff:"+ (tp1-tp2));
///....
float angle=Vector2.Angle (new Vector2 (1, 0), rotat);
if (angle > 45 && angle < 135) {
if (rotat.y > 0){
a+=3.0f;
if(a>180.0f)
a%=180.0f;
}
else{
a-=3.0f;
if(a<-180.0f)
a%=180.0f;
}
}
else {
if (rotat.x>0){
b+=3.0f;
if(b>180.0f)
b%=180.0f;
}
else{
b-=3.0f;
if(b<-180.0f)
b%=180.0f;
}
}
}
bTouched=true;
}
else
bTouched=false;
obj.transform.rotation = Quaternion.Euler (new Vector3 (a, b, c));
if((a<=-5.0f && a>=-25.0f) && (b<=80.0f && b>=60.0f)){
//若物件達到指定角度
over=true;
SceneManager.LoadScene ("start_menu");
}
}
}
2.過關條件判斷
因為我們程式的寫法是一直累加或減角度,導致最後數值會大於或小於360度,所以在做條件判斷時需將數值除以180取餘數,以取得正確的數值
if (angle > 45 && angle < 135) {
if (rotat.y > 0){
a+=3.0f;
if(a>180.0f)
a%=180.0f;
}
else{
a-=3.0f;
if(a<-180.0f)
a%=180.0f;
}
}
else {
if (rotat.x>0){
b+=3.0f;
if(b>180.0f)
b%=180.0f;
}
else{
b-=3.0f;
if(b<-180.0f)
b%=180.0f;
}
}
week14_焦焦焦
Week14 +1 notes
分開碰撞物件(把一個物件套一個程式) \文字版面



第一顆球 程式
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bom : MonoBehaviour
{
GameObject realBoard=null;
public GameObject board;
public GameObject BAT; //BAT手把
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
float x=0;
void Update()
{
}
void OnTriggerEnter(Collider collision)
{
print("collision");
if(realBoard==null) realBoard = Instantiate(board); //碰撞後秀出文字板
}
}


第二顆球 程式
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bom2 : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter(Collider collision)
{
print("collision22222");
}
}
第一顆球 程式
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bom : MonoBehaviour
{
GameObject realBoard=null;
public GameObject board;
public GameObject BAT; //BAT手把
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
float x=0;
void Update()
{
}
void OnTriggerEnter(Collider collision)
{
print("collision");
if(realBoard==null) realBoard = Instantiate(board); //碰撞後秀出文字板
}
}
第二顆球 程式
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bom2 : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter(Collider collision)
{
print("collision22222");
}
}
Week14_ㄩㄐ的快樂燒聲
Week 15 目標:
① 更新期末作品進度
開始在各方尋找能用的資源
後來將第三個網站的 transform.rotation = Quaternion.Euler(new Vector3(0f,90f,0f));
作為子彈的方向
① 更新期末作品進度
① 更新期末作品進度
▶ 校正子彈發射
↑參考自 Unity 设置物体旋转角度误区
開始在各方尋找能用的資源

後來將第三個網站的 transform.rotation = Quaternion.Euler(new Vector3(0f,90f,0f));
作為子彈的方向
↑ 參考自 Unity Transform.rotation 旋轉角度
▶ 場景微調
↑ 一些場景畫面和偵測回饋
week14
Camera rig
1. 調整場景大小、位置
雷射
1. 設定把手,按下Trigger會發出射線,要把物體加上collider
2. 放開Trigger射線會消失
竹籤設定
Rigidbody →Is Kinematic打勾
爐子設定
Rigidbody → Use Gravity打勾 → Is Kinematic打勾
使得竹籤不會穿越爐子
Week14
在VR中有幾種移動方式,我們一開始有考慮用順一的方式,但後來還是覺得用touchpad控制上下左右比較有操作感。但缺點就是會因為頭盔的轉向而導致座標軸的錯誤,這個問題是我們一開始考慮的點,而譽嘉則提出我們不做移動,而是以場景切換取代。但可能是這個提議,讓我們有了將關卡與密室主體分開的構想。
旋轉移動程式
手把控制 兩手trigger控制抓取物品
左手touchpad控制移動
訂閱:
文章 (Atom)






















