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 Miyahonmoto · Oct 11, 2020 at 08:11 AM · script.floaty-axisobstaclesinking

I still have the question that is not solved yet.

I know that it is against the rule of unity answer system but my problem isn't solve yet, therefore I just deleted previous post about similar question and I have to get answer for my problem.

My problem is that my obstacle in my game(which is rotating stage and move ball into a goal) is still floating or sinking when I rotate my stage, even I put my obstacle as child of stage. I already found out there 2(or 3) problems.

1: When I remove the programmed code of C#, there is no sinking or floating of obstacle anymore , therefore the problem must be in the my programmed code, and when I asked same question at the stack overflow, it says that "There is no requirement of updating the position of obstacle", but what is other way tp calculate vector of my obstacles?

2: When I talk this problem to my friend, he said that there might be some "edge case problem", but when I research this "edge case", I have no idea how I can solve this(I know it is vert bad thing that I need to apologize to him...) to my programmed code.

3 : When I asked same question to other webpages, (I think It was Unity Forum) It said that I should use Rigidbody.MovePosition, but Also, I have no idea how can I use although I researched about this.

I want to know these three questions to solve my problems of my child object is keeping floating or sinking.

Code for movement of obstacle

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 public class RepeatMovementOfShark : MonoBehaviour
 {
     public float zSpeed = -1.0f; //units per second, set negative to go the other way
     public float zDistance = 10.0f; //distance to travel before turning back
 
     private Vector3 startPos;
     
     float way = 1.0f;
     float zPos = 0.0f;
     float zPosPrev = 0.0f;
 
     float Distance;
 
     public Rigidbody Stage;
     public Rigidbody Shark;
 
     void Start()
     {
         //save start position
         startPos = transform.position;
 
     }
     void Update()
     {
         Movement();
 
         //handle turn around at end
         if (Mathf.Abs(zPos) > zDistance)
         {
             way = -way;
             zPos = zPosPrev;
         }
         //handle turn around at start
         if ((zPos < 0.0f && zPosPrev > 0.0f) || (zPosPrev < 0.0f && zPos > 0.0f))
         {
             way = -way;
             zPos = zPosPrev;
         }
         
         var SharkYPosition = Shark.position.y;
         var StageYPosition = Stage.position.y;
 
         Distance = SharkYPosition - StageYPosition;
 
         Debug.Log(Distance);
     }
 
     private void Movement() 
     {
         Vector3 currentPos = transform.position;
         //advance position
         zPosPrev = zPos;
         zPos += way * zSpeed * Time.deltaTime;
         //set new position
         transform.position = new Vector3(transform.position.x, transform.position.y, startPos.z + zPos);
     }
 }

I want any solution for these three questions to solve my obstacle stop sinking and floating by fixing the C# code above.

alt text

After I play the game , my obstacle starts sinking and floating like the picture above, I want to remain the distance between obstacle and stages all the time like picture shown below.

alt text

未た解決せす.png (60.3 kB)
正常な状態.png (63.9 kB)
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

168 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 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

Accuracy issues with Float (Vector3) 2 Answers

Realistic boat physics? 0 Answers

get obstacle speed to gradually increase 1 Answer

Trying to add value to a float in animator each time an animation plays. 0 Answers

How to make a float hold only entire numbers 2 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