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 DarKKendO · Jun 20, 2012 at 03:39 AM · physicsraycastcubepick up

Picked up cube passes through walls

Hey guys, Been searching the internet for hours and I can't figure out why this is happening. I have a scene with a first person character controller and a cube. The floor and 4 walls are all just stretched cubes. I have this script attached to the camera within the first person controller

 using UnityEngine;
 using System.Collections;

 public class PickUpObjectTest : MonoBehaviour {
 
 private Rigidbody rigid;                //For storing the rigidbody if successfully hit
 private int holdDistance;                //The distance that the object will be held away from the player
 private enum holdState {Free, Held};    //States in which the player can be regarding external objects
 private holdState state;                //State variable
 private float increment;                //The speed at which the object moves towards the camera
 private Quaternion rotation;            //The desired rotation of the object when picked up
 
 // Use this for initialization
 void Start () {
     holdDistance = 3;
     state = holdState.Free;
     increment = 1.0f;
 }
 
 // Update is called once per frame
 void FixedUpdate () {
     
     switch (state){
         
     case holdState.Free:
         if (Input.GetKey ("e")){
             Ray ray = camera.ScreenPointToRay(new Vector3(camera.pixelWidth/2, camera.pixelHeight/2, 0));
                Debug.DrawRay(ray.origin, ray.direction * 10, Color.yellow);
             RaycastHit hit;
             if (Physics.Raycast(ray, out hit, 10)){
                 if (hit.transform.tag == "Pickable"){
                     rigid = hit.rigidbody;
                     state = holdState.Held;
                 }
             }
         }
         break;
         
     case holdState.Held:
         
         Vector3 nextPos;
         
         if (increment < 100.0f)
             increment++;
         
         rigid.transform.parent = transform;
         
         nextPos = Vector3.Lerp(rigid.position, transform.position + transform.forward * holdDistance, increment);
         
         if (!Physics.Raycast(rigid.position, nextPos, 2)){
             rigid.position = nextPos;
         }
         
         //Rotation of the object
         Vector3 direction = transform.position - rigid.transform.position;
         rotation = Quaternion.LookRotation(direction);
         rigid.transform.rotation = Quaternion.Slerp(rigid.transform.rotation, rotation, increment);
         rigid.transform.rotation = Quaternion.Euler(rigid.transform.rotation.x,
             rigid.transform.rotation.eulerAngles.y, rigid.transform.rotation.eulerAngles.z);
         
         rigid.useGravity = false;
         
         if (Input.GetKey ("e")){
             increment = 1.0f;
             rigid.useGravity = true;
             rigid.transform.parent = null;
             state = holdState.Free;
         }
         break;
     }
   }
 } 

I can pick up the cube and move around the scene with it however when I look down at the ground or walk near a wall the cube passes right through it. I have tried walking very slowly towards the wall and the cube doesn't immediately pass through, rather it pops through when I get close enough. Any help would be IMMENSELY appreciated as I am trying to hold on to the few remaining strands of hair I have left :(

Thanks Guys

Comment
Add comment · Show 3
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 Ampler Games · Jun 20, 2012 at 03:57 AM 0
Share

I had a very similar problem with the drag ridgidbody script, I don't know why this happens but I found that if I made the wall have a ridgedbody but without gravity then change the wieght of the walls so they are really heavy, this fixed by problem.

avatar image DarKKendO · Jun 20, 2012 at 09:36 AM 0
Share

Tried that and thought that solved the problem. Then the walls started floating away!! haha. $$anonymous$$ight have to play around with it a bit today. $$anonymous$$ight mess around with some more physics ray casting and see what happens also

avatar image Unnamed · Aug 18, 2012 at 04:03 PM 0
Share

Hey. I'm having the exact same problem. Have you found a solution yet?

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by DarKKendO · Aug 23, 2012 at 09:07 PM

Solved this issue. I found the answer by modifying the script found in this thread:

http://forum.unity3d.com/threads/79352-Half-Life-2-Object-Grabber

Comment
Add comment · 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
0

Answer by djm · Jun 20, 2012 at 04:36 AM

Does the cube have "Is Trigger" enabled?

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 DarKKendO · Jun 20, 2012 at 09:35 AM 0
Share

Theres no triggers attached to the cube. Its just the standard one with a "pickable" tag added

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

6 People are following this question.

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

Related Questions

Make a rolling ball always on ground without falling when reaching the edges of the map 1 Answer

Physics.SphereCastAll with triggers 1 Answer

Raycasting to the bottom side of a plane? 2 Answers

Physics.CapsuleCast Help 1 Answer

Raycast stops working after ~40 seconds when target has Rigidbody 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