Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by DK86 · Aug 30, 2016 at 11:59 PM · scripting problemvrshootinggunsteam

Please help me solve the problem with shoot a gun(HTC VIVE)

How to attach shooting gun to my eyes???(HTC vive) When I press the button on the controller, it should fire from my eyes. But it doesn't work! please help me what to do!! I really need your help! Please save my life -------------> click on the link: https://youtu.be/_TYlZTRWirA

There are two scrips(1. VRYK_ObjectAutoGrab//2.Gun) to attach the gun to front view of camera. -------------------------------------------------------------------------------------------------------------------------------------------

// 1. VRYK_ObjectAutoGrab

namespace VRTK { using UnityEngine; using System.Collections;

public class VRTK_ObjectAutoGrab : MonoBehaviour { public VRTK_InteractableObject objectToGrab; public bool cloneGrabbedObject;

  private VRTK_InteractGrab controller;

  private IEnumerator Start()
  {
      controller = GetComponent<VRTK_InteractGrab>();
      if (!controller)
      {
          Debug.LogError("The VRTK_InteractGrab script is required to be attached to the controller along with this script.");
          yield break;
      }


      

      VRTK_InteractableObject grabbableObject = objectToGrab;
      if (cloneGrabbedObject)
      {
          grabbableObject = Instantiate(objectToGrab);
      }
      controller.GetComponent<VRTK_InteractTouch>().ForceStopTouching();
      controller.GetComponent<VRTK_InteractTouch>().ForceTouch(grabbableObject.gameObject);
      controller.AttemptGrab();
  }

} }

//2. Gun

using UnityEngine; using VRTK;

public class Gun : VRTK_InteractableObject { public static Camera main; private GameObject bullet; private float bulletSpeed = 2000f; private float bulletLife = 1f; private AudioSource gunAudio;

public override void StartUsing(GameObject usingObject) { main = GetComponentInParent(); base.StartUsing(usingObject); FireBullet(); }

protected override void Start() { gunAudio = GetComponent(); base.Start(); bullet = transform.Find("Bullet").gameObject; bullet.SetActive(false); }

private void FireBullet() { GameObject bulletClone = Instantiate(bullet, bullet.transform.position, bullet.transform.rotation) as GameObject; bulletClone.SetActive(true); Rigidbody rb = bulletClone.GetComponent(); rb.AddForce(-bullet.transform.forward * bulletSpeed); Destroy(bulletClone, bulletLife); } }

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mj321 · Aug 31, 2016 at 05:28 AM 0
Share

1) $$anonymous$$ake the gun a child of CameraRig, so that it moves and rotates with the camera 2) Remove the $$anonymous$$us sign from "-bullet.transform.forward", because the bullets are flying in the wrong direction.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DK86 · Aug 31, 2016 at 05:50 AM

I think it has something to do with the script(1.objectautograb). In that part, I need to arrange the transform and position to attach the object (gun) to Camera eyes (not comera body) Could you let me know how to do that????please?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mj321 · Aug 31, 2016 at 06:52 AM 0
Share

I don't have much experience with VR program$$anonymous$$g and i don't see the pickup logic in the code you posted. So i can only give some general hints.

Add a "public Transform camera_transform;" to the Gun script. In the editor drag the "Camera (eye)" object into the slot for that variable.

After the gun has been picked up, you need to perform these steps with the gun object:

 transform.SetParent( camera_transform );
 transform.position = camera_transform.position;
 transform.rotation = camera_transform.rotation;

Untested of course, but maybe this helps you to get closer to what you want.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

93 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to attach shooting gun to my eyes???(HTC vive) When I press the button on the controller, it should fire from my eyes. But I can't find the way!! please help me what to do!! Best regards, 1 Answer

2 Guns aren't meant to fire together but they do 0 Answers

SteamVR menu button stops coroutines when pressed. 2 Answers

How To Keep My Weapon With My Camera? 2 Answers

SteamVR Teleport causes Terrain to Disappear 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges