Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 unity_XnvR_07NFIOPjA · Nov 10, 2019 at 04:09 AM · velocitytransform.positiontransform.rotationtransform.parent

Resetting Ball Object to the original parent and position

So I am trying to reset a ball to its initial position and re-attach it to its original parent. I am learning coding and I am creating a mini baseball game, not for release, just for me to practice getting objects to do what I want. I have the ball successfully coming out of the pitchers hand (dropping from its parent which is the hand) and being pitched. I can successfully hit it. I have a collision set up that when the ball reaches the outfield it resets to initial state. What is happening is the ball looks like its a couple feet away from the pitchers hand after it resets, the pitcher still throws another pitch and I can hit it again, but it is always a couple feet away from the hand after the first pitch. Here is the part of the code that seems to not be working correctly, any help on what I am doing wrong?

 public class LaunchBall : MonoBehaviour
 {// launch variables
     [SerializeField] private Transform TargetObjectTF;
     [SerializeField] private Transform TargetHitTF;
     [Range(10.0f, 75.0f)] public float LaunchAngle;
     public GameObject Hitter;
     public GameObject Pitcher;
     public GameObject empty;
     public GameObject ball;
     
 
 
 
     // cache
     private Rigidbody rigid;
     private Vector3 initialPosition;
     private Quaternion initialRotation;
     
 
     //-----------------------------------------------------------------------------------------------
 
     // Use this for initialization
     void Start()
     {
         rigid = GetComponent<Rigidbody>();
         transform.parent = empty.transform;
         initialPosition =  transform.position;
         initialRotation = transform.rotation;
     }
 
     // resets the ball, batter, and pitcher to its initial position
     void ResetToInitialState()
     {
         LaunchAngle = 30.0f;
         GetComponent<Rigidbody>().useGravity = false;
         Pitcher.GetComponent<Pitcher>().ResetPitcher();
         transform.parent = empty.transform;
         transform.SetPositionAndRotation(initialPosition, initialRotation);
         Hitter.GetComponent<SwingScript>().ResetBatter();
         rigid.velocity = Vector3.zero;
 
     
     }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by unity_XnvR_07NFIOPjA · Nov 11, 2019 at 03:03 AM

I got it figured out. needed to use localposition instead.

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 bucketman5000 · Sep 12, 2021 at 11:47 AM

Hey could you explain what you did to figure this out? I also need to reset the exact pos and rot of my item back within its original parent

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

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

118 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

Related Questions

How to get updated Transform of a spawned object? 1 Answer

moving object while it has another movement 1 Answer

Velocity powered rigidbody on a moving platform without parenting. 3 Answers

Possible way to improve performance moving large hierarchies? 1 Answer

How Do I Give Two Objects the Same Transform? 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