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
3
Question by Ziad · Aug 18, 2011 at 10:45 AM · collisionmovingcollide

Making the object collide while moving in the forward dir. (Vector3.forward)

i'm making an object move in the forward direction i used this

         if (target)
     {
         var distance = Vector3.Distance(transform.position, target.position);
         transform.LookAt(target);
         if (distance > 2)
         {
             transform.position += transform.TransformDirection(Vector3.forward * Time.deltaTime * 10);
         }
     }


but the problem is that i want the object to collide with the other object but it doesn't

please tell me how to do it

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 Julien-Lynge · Aug 18, 2011 at 03:19 PM 0
Share

A simple question, but it has to be asked: do you have colliders on the two objects that you are trying to collide?

avatar image Joshua · Aug 18, 2011 at 04:21 PM 0
Share

What @NOAA_Julien asks + does the body you are trying to move have a rigidbody component?

1 Reply

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

Answer by Anxo · Aug 18, 2011 at 05:45 PM

You are telling the object where to go instead of allowing it to figure out where it needs to go. When you tell it

Transform.position +=...

It tells the object where it needs to be. So even if it collides with something, it can not stop because you are telling it "go here"

If you have a rigidbody and you wish to move it forward, but you want it to stop or bump into things that changes its velocity or direction, you will have to use "AddForce" You can check the documentation on how to use it but its something like

 private var ThisRigid : Rigidbody;
 function Start(){
 ThisRigid = rigidbody;
 }
 
 function Update(){
 ThisRigid.AddForce(Vector3.Forward*10*Time.deltaTime);
 }

or something liek that, again check the documentation, I am not around Unity.

If you have a character controller you need to use the Move function. in order to have it collide with stuff. Check Character Controller if this is the case.

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 Ziad · Aug 18, 2011 at 05:49 PM 0
Share

Thnx Dude, i fixed the problem an hour ago, i used the $$anonymous$$ove Function, but i marked ur question as a correct question ; cuz its a correct 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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Camera Colliding with Terrain 1 Answer

How to let the player collide with animated objects? 0 Answers

How to check if an object is colliding with another? 3 Answers

Moving Platform Collisions with Custom Movement Script 0 Answers

Complication with script 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