Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 /
  • Help Room /
avatar image
0
Question by whaleinthesea · Sep 07, 2015 at 01:26 PM · c#movementvector3movetowardssolid

How to make object solid with Vector3.MoveTowards?

I have a sphere which moves to my mouse position when I click on the screen. I also have a cube, now I can move trough the cube, but I want the cube is solid so I can`t move trough it. This is my code:

 public bool canMove = false;
 public Vector3 endPoint;
 public float duration = 50f;
 void Update(){
   if(Input.GetMouseButton(0)){
     canMove = true;
     endPoint = Input.mousePosition;
     endPoint.z = transform.position.z = Camera.main.transform.position.z;
     endPoint = Camera.main.ScreenToWorldPoint(endPoint);
   }
   if(transform.position == endPoint){
     canMove = false;
   }else if (canMove){
     transform.position = Vector3.MoveTowards(transform.position, endPoint, duration * Time.deltaTime);
   }
 }

How can I make the cubes solid so I can`t move trough it?

Sorry for bad formulated question.

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 RLin · Sep 07, 2015 at 01:41 PM 0
Share

What's with all of the strang numbers in your code? Try pasting it after clicking the 010101 button.

avatar image whaleinthesea · Sep 07, 2015 at 01:52 PM 0
Share

I don't know why, but the code syntax is not working 9 of the 10 times

avatar image RLin · Sep 07, 2015 at 01:55 PM 0
Share

It's working now.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by RLin · Sep 07, 2015 at 01:56 PM

Proud would probably have to add a rigid body and collides to make it so that the two are solid objects, and use addforce or set the rigid body velocity in order to mov the objects.

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 whaleinthesea · Sep 07, 2015 at 02:06 PM 0
Share

Thanks for your answer, but can you tell the code how I can move?

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

28 People are following this question.

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

Related Questions

Vector3.MoveTowards moving transform 0 Answers

Moving GameObject a specific distance in the Z direction and back again - regardless of rotation 1 Answer

Movement Sticking 0 Answers

How to make more realistic bot AI? 2 Answers

MoveTowards resets position 1 Answer


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