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 /
avatar image
0
Question by CeewhY · Jul 22, 2011 at 04:14 AM · gameobjectcolliderignore

game object ignores collider

var hit : RaycastHit; var raypoint : Vector3; var getcoor = false;

function Update(){ if(Input.GetButtonDown("Fire1")) getcoor = true; if(Input.GetButtonUp("Fire1")) getcoor = false;

 if (getcoor)

     {
     var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
     if(Physics.Raycast(Camera.main.ScreenPointToRay (Input.mousePosition), hit))
         {
             raypoint = hit.point;
             
         }
     }
 transform.position = Vector3.Lerp(transform.position, hit.point, Time.deltaTime);

} I am using this code to move my game object around on a plane. The code let me move my game object wherever I click. But the problem is, it (the game object) ignores anything that i put on the plane (e.g. going through colliders and etc...). Does anyone knows how to make the physics work? p.s: FYI, FixedUpdate() won't work too.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by aldonaletto · Jul 22, 2011 at 06:11 AM

If your object is not a Character Controller, just add a rigidbody and it will collide with other objects (I've just tested the script in my project). The default rigidbody (with Use Gravity checked and Is Kinematic unchecked) is OK.

EDITED: The Character Controller must be moved with Move or SimpleMove in order to detect collisions. I modified your original script to use a character controller, and cut out some redundancies (one Raycast instead of two, GetButton instead of GetButtonDown/GetButtonUp, etc.). Now it detects collisions, and also has a fake gravity (a constant down velocity instead of a real acceleration). The variable speed adjusts the moving speed (the actual velocity will be also proportional to the distance):

var hit : RaycastHit; var raypoint : Vector3; var speed = 10; // move speed var gravity = 10; // fake gravity

private var character: CharacterController;

function Start(){ character = GetComponent(CharacterController); raypoint = transform.position; }

function Update(){ if(Input.GetButton("Fire1")){ var ray = Camera.main.ScreenPointToRay (Input.mousePosition); if(Physics.Raycast(ray, hit)) { raypoint = hit.point; } } var dir = raypoint - transform.position; dir.y = -gravity; // applies a fake gravity character.Move(dir Time.deltaTime speed); }

Comment
Add comment · Show 2 · 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 CeewhY · Jul 22, 2011 at 06:35 AM 0
Share

it is a character controller, and i tried to add a rigidbody but it still go through anything else on the place, and moreover, when i move too much, the game object will go through the plana and fall down...

avatar image aldonaletto · Jul 23, 2011 at 12:53 AM 0
Share

I edited my answer to use a Character Controller, and added a fake gravity.

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

Ignore Collider 0 Answers

Destroying Game Object On MouseButtonDown + Distance Collision 0 Answers

Multiple Colliders Trigger problem 2 Answers

Change a GameObject's collider 1 Answer

Get collider from raycast 4 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