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 Samael_00001 · Jul 25, 2014 at 03:32 PM · movementsmoothball

Because of default SmoothFollo2D script my ball is not moving smoothly. How to fix that?

Video

Here is a code, attached to ball:

 void FixedUpdate () {
         if (Input.GetKey(KeyCode.RightArrow))
         {
             rigidbody.AddForce(Vector3.right * 5);
         }
 
         if (Input.GetKey(KeyCode.LeftArrow))
         {
             rigidbody.AddForce(Vector3.left * 5);
         }
     }


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

4 Replies

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

Answer by Samael_00001 · Jul 25, 2014 at 05:40 PM

 using UnityEngine;
 using System.Collections;
 
 public class CameraController : MonoBehaviour {
 
     public GameObject player;
     private Vector3 offset;
 
     // Use this for initialization
     void Start () {
         offset = transform.position;
     }
     
     // Update is called once per frame
     void LateUpdate () {
         transform.position = player.transform.position + offset;
     }
 }

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 gcoope · Jul 25, 2014 at 03:42 PM

Try

 rigidybody.AddForce(-Vector3.right * 5 * Time.deltaTime);

This will add a smooth update. You could also try putting it in just Update and see how it reacts.

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 Samael_00001 · Jul 25, 2014 at 03:44 PM 0
Share

the same thing..

avatar image
0

Answer by Nitrosocke · Jul 25, 2014 at 04:04 PM

Maybe you have luck with this code:

 #pragma strict
 
 var rotationSpeed = 100;
 
 function Update () {
 
     var rotation : float = rotationSpeed;
     rotation *= Time.deltaTime;
         
     if (Input.GetKey(KeyCode.LeftArrow)){        
         rigidbody.AddRelativeTorque (Vector3.left * rotation);
      }
      
      if (Input.GetKey(KeyCode.RightArrow)){
         rigidbody.AddRelativeTorque (Vector3.right * rotation);
      }
  }

I tried this in Unity and it seems like the Ball moves smooth. Give it a try.

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 Samael_00001 · Jul 25, 2014 at 05:09 PM 0
Share

that's nice, but it seems my left became my forward and my right became my backward o_O

avatar image
0

Answer by Vitor_r · Jul 25, 2014 at 04:03 PM

You shouldn't be listening for input on the FixedUpdate. You should listen for input on Update and apply the force on the FixedUpdate. Use a boolean to control this.

 void Update(){
     if (Input.GetKey(KeyCode.RightArrow)){
        moveRight=true
     }    
 }
 
 void FixedUpdate () {
     if (moveRight){
        moveRight=false;
        rigidbody.AddForce(Vector3.right * 5);
     }
      
 }
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 Samael_00001 · Jul 26, 2014 at 11:39 AM 0
Share

why? I want to know more)

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

25 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

Related Questions

Smooth rotation... 1 Answer

A node in a childnode? 1 Answer

Character Movement jitters 1 Answer

How to smoothen movement of a child object? 1 Answer

How can i drag objects smoothly with touch? Please help me with this code! 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