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
0
Question by skywaltzlabs.shikhar · Sep 11, 2015 at 04:55 PM · movementpositionparent-child

Movement while moving along with other object.

Hi,

I am currently working on a game like crossy road. Have you seen how player moves across planks in river? I want to do exactly like that.

Methods I have tried so far:-

  • parenting game character to the planks for movement along the x axis.

  • moving game character along with plank.

Character movement method I am using :-

  • In update I am moving character towards an Vector3 variable EndPosition which is updated on every input.

       void MoveForward()
         {
     //Next move position for player to move to 
             newMovePosition = new Vector3 (EndPos.x, Player.transform.position.y, EndPos.z+1);
     //Check if there is no obstacle in front 
             RaycastCheck (Vector3.forward);
     //Update next move position only if there in no obstacle
             if(AbleToMove)
             {
                 ContinueMove (newMovePosition);
                 ScoreControl.ScoreUpdate();
             }
         }
    

Similar for Left,Right and Backwards movement.

  • If I use temporary variable to update Next or End movement position, while player is on plank which is moving along X axis, so when player moves it updates its position from the spot it landed which is completely wrong.

  • If I update End position form player current transform.position it works but movement is not smooth while player moves left or right while its on plank or when he moves in and out of it. Sometimes character object moves double the amount of what it's supposed to move While moving left or right.

  • When I am moving character along with the plank, player gets stuck on its edge. as it dosen't completes it original movement and executes code to move along with it.

  • After every movement I am snapping its transform position so it stays in grid.

       //Check the from end position
         
         if ( Mathf.Abs(EndPos.z - Player.transform.position.z) < snapToGridDistance &&  Mathf.Abs(EndPos.x - Player.transform.position.x)<snapToGridDistance)
                 {
         
         //Snap player position so it stays in grid.
         
         Player.transform.position = new Vector3(Mathf.Round(Player.transform.position, Player.transform.position.y, Mathf.Round(Player.transform.position.z));
    
    

I have been stuck with this problem from past month. Please help.

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

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

How do you change a players position during an animation? 2 Answers

Moving an Object to the vector of other objects on button press using a vector3 array? 0 Answers

How to Have Projectile Reset to Initial Position Relative to Parent 1 Answer

Movement with iTween and parameter 0 Answers

Positioning problem when using hierarchy 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