- Home /
Google Cardboard Collider
Hi I am building an app where I can view and walk around a model (created in REVIT). This is my first time with unity so I am a newbie. Basically I am having trouble with the colliders I have had a third person character running around so I no the colliders I have attached to the walls work. I have attached a capsule to the cardboard main camera to stop the cameras going through the walls but this isn't working. I have tried attaching a capsule to all of the cameras but nothing seems to work. Can anyone suggest anything?
how are you moving the objects with the colliders? are you using vector translation or rigidbody physics? collisions only work with rigid bodies, if you use vectors additions then they will go through each other.
It would appear I am using vector translations. I need to change the script to rigid body movement. I am very new to this I am a Civil 3D user if anyone can help me with this I would be happy to generate a surface out of an existing topographical survey as a return favour. I just have no idea where to start.
Answer by beant0ad · Jul 29, 2015 at 09:41 AM
Thanks for the reply. I am using the following script for movement which I found off the internet.
// activate the autowalk function by pull the cardboard trigger, by define a threshold angle // or combine both by selecting both of these options. // The threshold is an value in degree between 0° and 90°. So for example the threshold is // 30°, the player will move when he is looking 31° down to the bottom and he will not move // when the player is looking 29° down to the bottom. This script can easally be configured // in the Unity Inspector.Attach this Script to your CardboardMain-GameObject. If you // haven't the Cardboard Unity SDK, download it from https://developers.google.com/cardboard/unity/download
using UnityEngine; using System.Collections;
public class Autowalk : MonoBehaviour { private const int RIGHT_ANGLE = 90;
// This variable determinates if the player will move or not
private bool isWalking = false;
CardboardHead head = null;
//This is the variable for the player speed
[Tooltip("With this speed the player will move.")]
public float speed;
[Tooltip("Activate this checkbox if the player shall move when the Cardboard trigger is pulled.")]
public bool walkWhenTriggered;
[Tooltip("Activate this checkbox if the player shall move when he looks below the threshold.")]
public bool walkWhenLookDown;
[Tooltip("This has to be an angle from 0° to 90°")]
public double thresholdAngle;
[Tooltip("Activate this Checkbox if you want to freeze the y-coordiante for the player. " +
"For example in the case of you have no collider attached to your CardboardMain-GameObject" +
"and you want to stay in a fixed level.")]
public bool freezeYPosition;
[Tooltip("This is the fixed y-coordinate.")]
public float yOffset;
void Start ()
{
head = Camera.main.GetComponent<StereoController>().Head;
}
void Update ()
{
// Walk when the Cardboard Trigger is used
if (walkWhenTriggered && !walkWhenLookDown && !isWalking && Cardboard.SDK.CardboardTriggered)
{
isWalking = true;
}
else if (walkWhenTriggered && !walkWhenLookDown && isWalking && Cardboard.SDK.CardboardTriggered)
{
isWalking = false;
}
// Walk when player looks below the threshold angle
if (walkWhenLookDown && !walkWhenTriggered && !isWalking &&
head.transform.eulerAngles.x >= thresholdAngle &&
head.transform.eulerAngles.x <= RIGHT_ANGLE)
{
isWalking = true;
}
else if (walkWhenLookDown && !walkWhenTriggered && isWalking &&
(head.transform.eulerAngles.x <= thresholdAngle ||
head.transform.eulerAngles.x >= RIGHT_ANGLE))
{
isWalking = false;
}
// Walk when the Cardboard trigger is used and the player looks down below the threshold angle
if (walkWhenLookDown && walkWhenTriggered && !isWalking &&
head.transform.eulerAngles.x >= thresholdAngle &&
Cardboard.SDK.CardboardTriggered &&
head.transform.eulerAngles.x <= RIGHT_ANGLE)
{
isWalking = true;
}
else if (walkWhenLookDown && walkWhenTriggered && isWalking &&
head.transform.eulerAngles.x >= thresholdAngle &&
(Cardboard.SDK.CardboardTriggered ||
head.transform.eulerAngles.x >= RIGHT_ANGLE))
{
isWalking = false;
}
if (isWalking)
{
Vector3 direction = new Vector3(head.transform.forward.x, 0, head.transform.forward.z).normalized * speed * Time.deltaTime;
Quaternion rotation = Quaternion.Euler(new Vector3(0, -transform.rotation.eulerAngles.y, 0));
transform.Translate(rotation * direction);
}
if(freezeYPosition)
{
transform.position = new Vector3(transform.position.x, yOffset, transform.position.z);
}
}
}
My coding skills are zero I am afraid to say and this was the best solution for me to move by looking down without having to pay on the asset store. Is there anyway I can get the colliders to work with this script?
no, because you modify the transform directly. In order to collide with walls, you will need to use the RigidBody component.
Your answer
![](https://koobas.hobune.stream/wayback/20220611233407im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Cardboard for Unity is cross-eyed 1 Answer
Unity profiler causing Gear VR ... Make sure the APK is signed exception? 1 Answer
toggle VRSettings 1 Answer
Multiplayer VR with Cardboard? 1 Answer