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 Dqimass · Apr 08, 2016 at 09:43 AM · c#rotationgameobjectplayertransform.parent

how do i get my player get sucked into a gameobject

I have a Rotating object that float back and forth in a platform game. I needed my player to jump in it and shoot his way to the next platform. I got the jump in half worked( I had help with that cause i'm still kind a new), but the only problem I have is when the player jump into the rotating Object, the player being swing around the rotating object instead of staying INside the object. This is the script i'm using

 void OnTriggerEnter2D(Collider2D other)
 {
     GameObject.FindGameObjectWithTag("Player").GetComponent<SpriteRenderer>().enabled = false;

     if (other.gameObject.CompareTag ("Player")) 
     {
         other.gameObject.transform.parent = transform;
     }
 }

How do I make the player get sucked inside the floating rotating object and have the player just follows it without going crazy?

Comment
Add comment · Show 2
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 Abhiroop-Tandon · Apr 08, 2016 at 02:34 PM 0
Share

You sure you have isTrigger enabled on the object ?

avatar image Dqimass Abhiroop-Tandon · Apr 09, 2016 at 02:30 AM 0
Share

yeah I do have the trigger set on

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Ckboyd89 · Apr 08, 2016 at 02:46 PM

From reading your description, I think that the "swinging" you are referring to is due to the player object being offset when it becomes childed to the rotating object. If you'd like to have the object stick to the origin of the rotating object, you simply need to get rid of the local offset, by adjusting the localPosition of the player. It should look like such:

 void OnTriggerEnter2D(Collider2d other)
 {
      if(other.gameObject.CompareTag("Player"))
      {
           other.gameObject.GetComponent<SpriteRenderer>().enabled = false;
           other.gameObject.transform.parent = transform;
           other.gameObject.transform.localPosition = new Vector3(0f,0f,0f);
      }
 }

Similarly, you can do the same with rotation, if you'd like to align the player.

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 Dqimass · Apr 09, 2016 at 02:54 AM

@Ckboyd89 Aww... it didn't work still.... my Playerobject is still being swung around like it got caught by a hurricane when it jumped into the Rotatingobject. I even tried turn off the rotation from the Rotatingobject and test it out, the Playerobject actually fall through it when it collides. This is what i'm using on the RotatingObject

 public float amplitude;           
 public float speed;                   
 private float startPosition;
 private Vector3 tempPos; 

 void Start () 
 {
     startPosition = transform.position.y;
     tempPos = transform.position;  
 }

 void Update ()
 {
     tempPos.y = startPosition + amplitude * Mathf.Sin (speed * Time.time);
     transform.position = tempPos;
     transform.Rotate (0, 0, 300 * Time.deltaTime);
 }

 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.CompareTag ("Player")) 
     {
         other.gameObject.transform.parent = transform;
         //other.gameObject.GetComponent<SpriteRenderer>().enabled = false;
         other.gameObject.transform.localPosition = new Vector3 (0f, 0f, 0f);
         other.gameObject.transform.localRotation = Quaternion.identity;
 
     }
 }

}

The PlayerObject is the one with the tag "Player".
So, is there a way maybe i can freeze the PlayerObject into the Rotatingobject? My player don't really have to rotate or anything, just as long as the Playerobject look like it's behind the Rotating object, it good. Sorry if i'm being complicated and my bad English

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

GameObject not looking at me.. 1 Answer

Status Effect Help 0 Answers

Undesired Angles with transform.Rotate(...) 0 Answers

[C#] Rotate player to camera forward look 0 Answers

Some problems with handmade basic player controller 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