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 /
  • Help Room /
avatar image
0
Question by gooodpgr · Aug 06, 2017 at 04:21 PM · camerakinematicrigid body

Camera shaking problem when player jump and stay on the moving platform

Hello I am new to here.And I had search many artcles for this issue , but still don't know how to solve this issue correctly.

I move my player in FIxedUpdate , using rigidbody.addForce (interplate of rigidbody is set to "interplate" ,and physics material of capsule collider is no friction because I don't want it to get stuck when touching other collider).

I move camera in LateUpdate. (call doPosFollow) alt text

I move platform in FixedUpdate (platform has rigidbody and iskinematic of it is true). And platform also has a trigger to set my player become child of platform. alt text

The film is link bellow to show the shaking problem of camera. https://www.youtube.com/watch?v=qrj-kFuClYU

The white box is using "rigid.movePosition". it looks more smooth, but when I parent my player to it, player will not move along with the platform.

The yellow box is using "transform.position" to set value directly. but when i parent my player to it,although player will move along with it, but the shaking problem of camera occures.

At the end of the film I speed up the moving speed of camera to avoid shaking problem . But when player is standing on yellow box , we can see the yellow box is in the vibration.

What is the correct method to operate the movingPlatform ? I am really a super mario fan.

camerapivot.jpg (157.4 kB)
sinmove.jpg (112.3 kB)
Comment
Add comment · Show 1
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 gooodpgr · Aug 07, 2017 at 11:04 AM 0
Share

https://www.udemy.com/create-a-2d-game-in-unity/

I find another method in this tutorial. Although he is not using rigidbody, but I am . (and he update character in LateUpdate)

  public Transform platform;
    public void setPlatform(Transform taget)
   {
      platform = taget;
      recordPos();
    }
    public void clearPlatform()
   {
      platform = null;
    }
 
     Vector3 recordPosLocal;
     Vector3 recordPosWorld;
     public Vector3 diff;
     void syncPosOnPlatform()
     {
         if (platform == null)
             return;
 
         Vector3 newPosWorld =platform.TransformPoint(recordPosLocal);
         diff=newPosWorld - recordPosWorld;
         transform.position += diff;
     }
 
     void recordPos()
     {
         if (platform == null)
             return;
 
         recordPosWorld =transform.position ;
         recordPosLocal = platform.InverseTransformPoint(recordPosWorld);
     }
    

s$$anonymous$$d of setting parent, His method is find the diff of position. setPlatform/clearPlatform is called in OnTriggerEnter/OnTriggerExit. syncPosOnPlatform and recordPos are called in FIxedUpdate of my player.

When I jump to yellow box , vibration still occurs.

When I jump to white box , the player moves bigger than diff of position, Like in a escalator .

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by gooodpgr · Aug 09, 2017 at 11:54 AM

There is another method.

https://docs.unity3d.com/ScriptReference/Rigidbody-position.html

And I made the following changes.

(1)all moving platform using "rigid.position = newPos;" to move.

(2)move my player still using addForce in FixedUpdate

(3)move my camera in FIxedUpdate (my old code is in LateUpdate)

(4)set interplate of rigidbody is "None"

(5)set parent is not useful when (1) , so I adjust position of player by recording deltaPostion of moving platform.

(6)NPC has rigidboy must set interplate of rigidbody is "None" too, otherwise the NPC will vibrate when player push him.

 public class RecordPositionDiff : MonoBehaviour {
 
     [SerializeField]
     RecordPositionDiff helper;
     Vector3 oldPos;
     Vector3 diff;
     private void Awake()
     {
         oldPos = transform.position;
     }
 
     // Update is called once per frame
     void FixedUpdate () {
 
         Vector3 newPos = transform.position;
         diff = newPos - oldPos;
         oldPos = newPos;
     }
 
     void OnTriggerEnter(Collider other)
     {
         if (!TagDefined.canOnMovableSet(other.gameObject.tag))
             return;
 
         PlanetPlayerController controller = other.gameObject.GetComponent<PlanetPlayerController>();
         if (controller != null)
             controller.setPlatform(this);
     }
 
     void OnTriggerExit(Collider other)
     {
         if (!TagDefined.canOnMovableSet(other.gameObject.tag))
             return;
 
         PlanetPlayerController controller = other.gameObject.GetComponent<PlanetPlayerController>();
         if (controller != null)
             controller.clearPlatform();
     }
 
     public Vector3 getDiff()
     {
         return diff;
     }
 
     public Vector3 getHelperDiff()
     {
         Debug.Assert(helper != null);
         return helper.getDiff();
     }
 }

 public class PlanetPlayerController
 {
 RecordPositionDiff platform;
 void syncPositionByPlatform()
     {
         if (platform == null)
             return;
 
         transform.position += platform.getDiff();
     }
 
     void FixedUpdate()
     {
         //...
         syncPositionByPlatform();
 
        //...
     }
 
 }

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 gooodpgr · Aug 09, 2017 at 12:05 PM 0
Share

oh,There is no diffrent when I using "rigid.position = newPos;" or "transform.postion=newPos;" to move platform.

avatar image gooodpgr · Aug 09, 2017 at 12:14 PM 0
Share

when using "transform.postion=newPos;" to move platform, "set parent" method could be working now. Otherwise is not

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

146 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Camera Reset Script 1 Answer

How to see a prefab from inside it? 1 Answer

How can I change the viewport rect of two active cameras at runtime? - Splitscreen Multiplayer 1 Answer

how to resize my orthographic Camera to fit a dynamically generated grid of cubes(Mine Sweeper) 0 Answers

Sprite showing up in camera but not showing up in game view 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