c# - Steering object by head VR Cardboard -
can tell me how head based steering? know how while mooving camera, want moove object head , camera follow object. need because want implement game logic object(it aleso work me if can treat camera normal object).
i found code steering camera:
public float speed = /* number */; private cardboardhead head; void start() { head = // find cardboardhead // example: // head = camera.main.getcomponent<stereocontroller>().head; // or, make variable public , use drag-and-drop in editor } void update() { transform.position += speed * head.gaze.direction; } i'm starting make games unity if made mistakes please correct me.
are using cardboard plugin unity here? https://developers.google.com/cardboard/unity/download
if do, there prefab called cardboard main, put in scene, if see there game object called head inside , contains cardboardhead script. here in script:
public gameobject head; // drag head gameobject here or can start void start() { if (!head) // if didn't drag gameobject { head = findobjectoftype<cardboardhead>().gameobject; } } void update() { transform.position += speed * head.transform.forward; // better multiply time.deltatime } also btw why tagged java?
new questions:
so here did. split 'visual' , 'mechanic'. removed mesh renderer player, freeze rotation rigidbody. made new child 'visual' has script called rotate.cs , removed collider.
changes script: in forward.cs use rb.addforce(transform.forward * speed); back, , in rotate.cs use
void update () { transform.rotate(vector3.right * 5); } that quickest solution can think of, i'm sure there other solutions can try

Comments
Post a Comment