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 WesterlyCarrot9 · Mar 11, 2013 at 06:51 PM · c#camerarigidbodycollidershaking

Collider/Rigidbody issue.Camera shaking!

So i have two cubes in my scene, one is the player who has a click to move script enabled and a rigidbody, and the other is the enemy who of course has a collider. The problem here is that i don't know how to make the player stop at a certain distance before the enemy so now he just crashes on the enemy and the whole camera shakes. Is there a solution for that?

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

3 Replies

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

Answer by Khada · Mar 12, 2013 at 03:29 PM

Sure, something like this should work:

 Vector3 startPoint;
 Vector3 endPoint;
 float moveDist;
 
 void Update()
 {
     //on mouse click
     if(Input.GetMouseButtonDown(0))
     {
         endPoint = //whatever code you use to calculate the point to move to
 
         //store the point where we are starting our new move
         startPoint = transform.position;
 
         //store the distance between the start point and end point
         moveDist = (startPoint - endPoint).magnitude;
     }
 
     //if not at target move point
     if(transform.position != endPoint)
     {
         //direction to move towards end point
         Vector3 dir = (endPoint- transform.position).normalise;
 
         //move towards end point
         transform.position += dir * Time.delateTime;
 
         //current distance from start point
         float dist = (transform.position - startPoint).magnitude;
 
         //if we have moved a distance greater than we should have
         if(dist > moveDist)
             transform.position = endPoint; //set us to target point
     }
 }
Comment
Add comment · Show 6 · 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 WesterlyCarrot9 · Mar 12, 2013 at 03:37 PM 0
Share

Hey thanks for that awesome answer. But where do i put the script?on the player right? And actually i get some errors that semicolons are missing :S Did you check that ClickTo$$anonymous$$ove script i use? http://wiki.unity3d.com/index.php/Click_To_$$anonymous$$ove_C

avatar image Khada · Mar 12, 2013 at 03:44 PM 0
Share

On the line:

 endPoint = //whatever code you use to calculate the point to move to

you are supposed to replace the comment with whatever code you use to give the player a location to move to. Read through the comments and see if you can understand how it works, then work it into your project. It's up to you to work the solution into your specific code.

avatar image Khada · Mar 14, 2013 at 01:10 AM 0
Share

Have you gotten things working? Can you tick the answer if it's correct or post the answer yourself. This helps keep the site clean and give credit to those who take the time to help.

None of the 14 questions you've asked have had any answers be marked as correct. Please go through those and take a moment to give credit, where due, to the volunteers who give their time.

avatar image WesterlyCarrot9 · Mar 14, 2013 at 06:31 AM 0
Share

You are right. I forgot about this. But it says i have to log in as another user to Like :S

avatar image WesterlyCarrot9 · Mar 14, 2013 at 06:36 AM 0
Share

Nvm i can do it now :P

Show more comments
avatar image
0

Answer by NikVel · Mar 27, 2016 at 01:54 PM

use FixedUpdate() in Camera script! It will fix problem/

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 Khada · Mar 27, 2016 at 02:21 PM 0
Share

No, it won't. Re-read the question to see why. And you've necro'd a 2 year old thread which is generally considered uncool.

avatar image thesythel · Dec 16, 2018 at 10:37 PM 0
Share

this fixed my problem

avatar image
0

Answer by programmrzinc · Mar 11, 2013 at 07:17 PM

The camera is shaking because the target of the camera is the Rigidbody Center of mass. Change the target to the Gameobject to fix this.

Comment
Add comment · Show 3 · 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 WesterlyCarrot9 · Mar 11, 2013 at 07:27 PM 0
Share

Are you sure it is going to work?any idea how to make the player sto in front of the enemy at a certain distance?

avatar image programmrzinc · Mar 11, 2013 at 09:28 PM 0
Share

Can I see your script that controls the Player? I do not have a bearing on what is happening

avatar image WesterlyCarrot9 · Mar 12, 2013 at 03:34 AM 0
Share

It is not working unfortunately. I cannot change the target of the camera because the game i try to make is a dungeon cralwer action RPG (Diablo-style) and the camera needs to have the player as a target all the time. I use this script here to move my player. It's a ClickTo$$anonymous$$ove script...http://wiki.unity3d.com/index.php/Click_To_$$anonymous$$ove_C

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

14 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

Related Questions

Why object goes sometimes through walls by adding force ? 2 Answers

view bounds perspective camera 1 Answer

Camera Collision Not Working 0 Answers

Question about topdown-movement and mouse-facing-foward-check 0 Answers

How to make main camera move towards player if it hits a game object. 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