Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 THEMASTERNOOB · Mar 28, 2012 at 06:08 PM · movementboxpick up

Box Pick up and movement

Hey, I have figured out picking up the box and moving it around however I still need a good way to detect if I am looking at the box. right now I have a trigger added to my camera and I am using

 Function OnTriggerStay()

however it is not always detecting when the trigger is in a box

here is the script that I am using to interact with the boxes

 function Update(){
 
     if(Input.GetKeyDown(KeyCode.F)){
 
         boxaction = true;
 
     }else if(Input.GetKeyUp(KeyCode.F)){
 
         boxaction = false;
 
     }
 
 }
 
 
 
 function OnTriggerStay(other : Collider){
 
     Debug.Log("collider is in box");
 
     Debug.Log(other.tag);
 
     Debug.Log(this.tag);
 
     var clone : GameObject;
 
     cube = other.collider.gameObject;
 
     if (other.collider.tag == "Cube" && boxaction && cubehold == false){
 
         cubehold = true;
 
         clone = Instantiate(cube, cube.transform.position, cube.transform.rotation);
 
         Destroy(cube);
 
         clone.transform.parent = Camera.main.transform;
 
         clone.rigidbody.isKinematic = true;
             
 
     }else if(other.collider.tag == "Cube" && boxaction == false){
 
         cubehold = false;
 
         other.transform.parent = null;
 
         other.rigidbody.isKinematic = false;
 
     }
 
 }

Why is the trigger attached to the camera not always detecting the box?

Also I am having problems that when I pick my boxes up the mesh tends to deform, does anyone know why this is and how I can stop it?

Any help would be appreciated. Thanks

Comment
Add comment · Show 5
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 roamcel · Apr 10, 2012 at 04:26 PM 0
Share

It is quite unclear what is happening and how. Please at least describe the scene in a few words. One can't tell 'what' picks up. The mouse? The player? Where is the script attached?

avatar image AlucardJay · Apr 10, 2012 at 05:05 PM 1
Share

with the mouse :

 private var imSelected : Transform;
 private var imClickedOn : boolean = false;

 // in function
     
     if (Input.Get$$anonymous$$ouseButtonDown(0)) 
     {        
         var rayHit : RaycastHit;
         if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), rayHit)) 
         {
             imSelected = rayHit.transform;
             if (imSelected == this.transform) {imClickedOn = true;}
         }
     }
avatar image Kleptomaniac · Apr 10, 2012 at 05:08 PM 0
Share

You should swap around your Get$$anonymous$$ouseButtonDown and Raycast statements. Probably better performance if the ray is only initiated with a mouse down event.

avatar image AlucardJay · Apr 10, 2012 at 05:19 PM 0
Share

done. when do you get mod status to fix my errors?!

avatar image THEMASTERNOOB · Apr 10, 2012 at 05:26 PM 0
Share

Hey, Thanks for the answers. What I am looking for is something like in portal or half life, were you look at a object and hit "e" and then you can move it around and place it where ever you want.

example(http://www.youtube.com/watch?v=UjAp$$anonymous$$HyEGTc)

The scene is: you are standing in a room with 3 cubes and a raised floor. To get on the raised floor you need to stack the cubes so you can jump up them and on to the raised floor. does that help? I guess I should have been a little more specific. also I have the script attached to the main camera.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Apex5 · Apr 10, 2012 at 08:36 PM

Be aware that OnTriggerStay only registers colliders that have entered it (and have a rigidbody attached); for example if the box starts in the trigger OnTriggerStay will not be called, I would imagine similar things would happen if you teleported the box in without crossing the threshold so to speak.

The way you're going about this seems a bit weird, e.g.

 clone = Instantiate(cube, cube.transform.position, cube.transform.rotation);
 Destroy(cube);

is meaningless as you're creating a copy of the cube at the exact same position/rotation and then destroying the original, effectively doing nothing; parenting the cube is fine but since you don't move it anywhere ( e.g. to the position of the player's "hands") it might stay out of your trigger's range anyway since it's not getting any close to the player.

In terms of telling what you're looking at you can use a raycast with the Camera's position+forward and then get the gameObject from that. I suggest looking up a full tutorial for this rather than trying to mash together pieces of different people's code (imo).

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 THEMASTERNOOB · Apr 13, 2012 at 01:11 PM 0
Share

Yeah the way I was doing was rather weird, I rewrote it using raycasting and it is detecting the boxes much more reliably, anyway thanks for answering my question.

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

7 People are following this question.

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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

how to move box if there is no box in front 2 Answers

Making a bubble level (not a game but work tool) 1 Answer

Movement from box to box 1 Answer

How to move only one object, not multiple objects 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