Dive Board



Crosshair for VR

Crosshair for VR

by Sephiroth on Apr 6th, 2014 23:59 PM

Read somewhere about how a static crosshair isn't suitable for VR since your eyes won't be focusing on the same distance as the crosshair. Might have been the Oculus guide...

So it needs to be dynamic. I wrote a little script that attaches to the 'Dive Camera' that makes a dynamic crosshair by using a raycast to measure the distance ahead and then moves an object to that position. This way the crosshair is always positioned at the distance your eyes are focused.

It also resizes the object so that to the viewer it looks static. It doesn't look like it's moving closer and further away from you, even though it really is.

The effect is quite nice and has no noticable impact on performance. It can also change color if it hovers over certain objects (like an enemy or power up ect).

for the crosshair I'm just using a sphere with the GUI/Text shader that is a child of the 'Dive Camera'. This shader is visible through other objects so isn't obscured if the crosshair is partially buried in another object.

crosshair.js

<br /><br />//crossHair game object should use the GUI/Text shader<br />var crossHair &#58; GameObject;<br /><br />function Update () {<br />	crossHairs ();	<br />}<br /><br />function crossHairs () {<br />	var crosshairPosition = transform&#46;position;<br />	var crosshairHit&#58; RaycastHit;<br />	var crosshairRay &#58; Ray = new Ray(crosshairPosition, transform&#46;forward);<br />	if (Physics&#46;Raycast(crosshairRay, crosshairHit)) {<br />		var crosshairDistance = crosshairHit&#46;distance;<br />		var crosshairPoint = crosshairHit&#46;point;<br />	}<br /><br />	// increasing the crosshairDistance multiplier increases the size of the crosshair<br />	crossHair&#46;transform&#46;localScale = new Vector3(crosshairDistance*0&#46;005, crosshairDistance*0&#46;005, crosshairDistance*0&#46;005);<br />	crossHair&#46;transform&#46;position = crosshairPoint;<br />	<br />	// Change 'Enemy' to the name of the object you would like to make the crosshair change color<br />	if (crosshairHit&#46;collider&#46;name == &quot;Enemy&quot;) {<br />		crossHair&#46;renderer&#46;material&#46;color = Color&#46;red;<br />	} else {<br />		crossHair&#46;renderer&#46;material&#46;color = Color&#46;white;<br />	}<br />		<br />}<br /><br /><br />


Example (the little white dot in the center) :

Short Distance


Long Distance :

Sephiroth

Posts: 45

Joined: 17.03.2014

dive-owner


Re: Crosshair for VR

by hikitax845 on May 14th, 2023 11:43 AM

Interesting and amazing how your post is! It Is Useful and helpful for me That I like it very much, and I am looking forward to Hearing from your next.. World of Woodcraft

hikitax845

Posts: 1484

Joined: 29.09.2022


Re: Crosshair for VR

by hikitax845 on May 21st, 2023 15:53 PM

Good job for publishing this kind of beneficial web site. Your online log isn't only useful but it is additionally really creative too. ponizej 2

hikitax845

Posts: 1484

Joined: 29.09.2022


Re: Crosshair for VR

by hikitax845 on May 27th, 2023 12:39 PM

Thanks because you have been willing to talk about information with us. we shall always appreciate all you have done here because I am aware you're very focused on our. letyshops kod polecajacy

hikitax845

Posts: 1484

Joined: 29.09.2022


Re: Crosshair for VR

by jacker on Jun 18th, 2023 11:53 AM

共度的高品質時光創造了珍貴的回憶,加強了情感連結。正确使用犀利士CIALIS犀利士常見的副作用可能包括頭痛、消化不良、背痛、肌肉疼痛和臉紅。 Cialimall.com

jacker

Posts: 28222

Joined: 27.10.2022


Re: Crosshair for VR

by jacker on Jun 19th, 2023 10:18 AM

A prescription for Cialis ensures that users are aware of potential drug interactions and their implications. 透過處方獲得犀利士確保使用者了解潛在藥物相互作用及其影響。 犀利士台灣官網

jacker

Posts: 28222

Joined: 27.10.2022


Re: Crosshair for VR

by jacker on Jun 20th, 2023 08:28 AM

The a truly great place That i experienced owing to publish it all. The chances of what precisely I want to observe pray during near future you can expect to keep going meant for posting an extremely good place. puerto morelos all inclusive

jacker

Posts: 28222

Joined: 27.10.2022


Re: Crosshair for VR

by asdfghjk on Dec 31st, 2023 07:06 AM

Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. ทางเข้า ufabet มือถือ

asdfghjk

Posts: 589

Joined: 04.12.2023


Re: Crosshair for VR

by asdfghjk on Dec 31st, 2023 08:15 AM

Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. ufabet เว็บหลัก ทางเข้า

asdfghjk

Posts: 589

Joined: 04.12.2023


Re: Crosshair for VR

by asdfghjk on Dec 31st, 2023 08:35 AM

Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. วิธีสมัคร ufabet

asdfghjk

Posts: 589

Joined: 04.12.2023


STATISTICS


Total posts: 144357


Total topics: 34841


Total members: 42384


Newest member: Daniel G.