Jump to content

instatiate gameobject


1128
 Share

Recommended Posts

how can i instantiate gameobject at raycast hit point from the controller

here is my code but unable to get result

 

public GameObject controller_right; // controller loader 

private void Update()
{

 

RaycastHit hit;
Vector3 c_pos = controller_right.transform.position;
Vector3 direction = controller_right.transform.forward;
Debug.DrawRay(c_pos, direction, Color.red);
if(Physics.Raycast(c_pos,direction, out hit))
{
display.text = hit.transform.gameObject.name.ToString();
if(hit.point != null)
{
if(WaveVR_Controller.Input(WVR_DeviceType.WVR_DeviceType_Controller_Right).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Trigger))
{
GameObject obj = Instantiate(sphere);
obj.transform.position = hit.point;
}
}

}

 

(  - Tag added by moderator) 

Link to comment
Share on other sites

Hi  ,

 

In current SDK, it's not supported to get position of hit point, and we have plan into next release.

Here is the short-term solution (with sample code) for your reference.

 

1. Please download and unzip the file (WaveVR_RaycastResult.zip) and put on the directory:

Assets/WaveVR/Scripts/EventSystem/

Then modify WaveVR_ControllerInputModule.cs by adding the code ( see red color session)

 

2. Modify your code as below:

 

                WaveVR_RaycastResult result = WaveVR_RaycastResultProvider.Instance.GetRaycastResult (
                WaveVR_Controller.GetEDeviceByWVRType (WVR_DeviceType.WVR_DeviceType_Controller_Right)    // right controller
            );

            Debug.Log ("World position of hit: " + result.worldPosition);
            Debug.Log ("Gameobject of hit: " + result.gameObject);

 

Let me know if it's helpful for you.

Thanks.

Link to comment
Share on other sites

thank you , i will try your suggest some other time but for now i made "controller prefab " gameobject from controllerloader script as public and casting ray from that gameobjects position and rotation.

 

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...