Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
avatar image
0
Question by MetalsGames · Mar 09, 2015 at 09:17 AM · cameraraycasttransformobjectmouseclick

Push object in direction of camera

Hello everyone, Im trying to get my First Person View Player to be able to walk up to a game object that is tagged "Nudge" or "Pushable" and that game object you click on should move in the direction you pushed it in. By the way, I have a ray cast that is shooting out from the center of the screen to pick up items and activate things. any help is much appreciated thanks in advanced.

here is my code.

 #pragma strict
 
 /*     NOTES
     
     Tags
     Movable = Item That can be picked up and movied around
     Nudge = Item that can be Nudge to create noise
     Pushable = Item that can be pushed greatly to knock over items
     PickUp = Item that can be picked up and placed in a hand or consumed
 */
 
 var PlayerCamera : GameObject;                   // The First Person Camera
 static public var Batteries : int; 
 static public var LeftHandObject : GameObject; // Object Currently in the Left Hand
 static public var RightHandObject : GameObject;// Object Currently in the Right Hand
 static public var LeftHandSOCKET : GameObject; // Left Hand SOCKET
 static public var RightHandSOCKET : GameObject;// Right Hand SOCKET
 var GrabDistantce : int;                        // The distants you must be in to grab item
 var LeftHandFull : boolean; 
 var RightHandFull : boolean;
 
 function Start ()
 {
     if(LeftHandSOCKET == null)
     {
         LeftHandSOCKET = GameObject.Find ("SOCKET_LeftHand");
     }
     if(RightHandSOCKET == null)
     {
         RightHandSOCKET = GameObject.Find ("SOCKET_RightHand");
     }
 }
 function Update () 
 {
     //Right Hand Grab Item
     if (Input.GetButtonDown("Fire2") && RightHandFull == false)
     {
         // Raycast for Right Hand Grab
         var RightHandcam : Transform = PlayerCamera.GetComponent.<Camera>().main.transform;
         var RightHandray = new Ray(RightHandcam.position, RightHandcam.forward);
         var RightHandhit : RaycastHit;
         
         if(Physics.Raycast (RightHandray, RightHandhit, GrabDistantce)) 
         {
             // RightHandObject = object you grabed
             RightHandObject = RightHandhit.collider.gameObject;
             
             if (RightHandhit.collider.gameObject.tag == "Movable")
             {
                 
                 PutItemInRightHand();
             }
             
             if (RightHandhit.collider.gameObject.tag == "Nudge")
             {
                 // This is where i need to put the code to activate the nudge force.
             }
             
             if (RightHandhit.collider.gameObject.tag == "Pushable")
             {
                 //Should be same as Nudge code just with more force.
             }
             
             
Comment
Add comment · Show 2
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 AlwaysSunny · Mar 09, 2015 at 04:10 AM 1
Share

When posting a question, please phrase your desire in the form of a question. I have no idea what you're asking. Also, posting only the relevant code will improve your odds of getting help.

avatar image MetalsGames · Mar 09, 2015 at 05:03 AM 0
Share

Thanks, I updated the question.

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Start raycast from object 1 Answer

Child instantiated object to RayCastHit's parent. 1 Answer

How To Detect MouseClick Using Raycast Java Script 0 Answers

Camera Orbiting Character: How to make an object move with another with no rotation 1 Answer

Camera Zoom in&out 2 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