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 ultimate1999 · Feb 24, 2020 at 09:16 PM · playercharactergamescalemoving platform

My player changes it original scale when on a moving platform..please help.THanks

hello guys, so i am working on a school project on unity and i am having a problem with my player...i have lot of moving platform on my project and i need my player to be to attached on the moving platform but the problem is that whenever my player is on the platform my player changes it orginal scale to some random scale..please i need help..i have read some answers related to to my question but up till now non of it works ...please i need help fast...THANKS

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
1
Best Answer

Answer by QPUNeptune · Mar 07, 2020 at 06:39 PM

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class AttachPlay : MonoBehaviour
 {
    
     public GameObject Player;
 
     private void OnTriggerEnter(Collider other)
     {
         if (other.gameObject == Player)
         {
             Debug.Log("touch");
             Player.transform.parent = transform;
 
         }
     }
 
     private void OnTriggerExit(Collider other)
     {
         if (other.gameObject == Player)
         {
             Player.transform.parent = null;
             Player.transform.localScale = DefaultScale.defaultScale;
         }
     }
     
 }

original code from @ultimate1999

The solution:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class AttachPlay : MonoBehaviour
 {
    
     public GameObject Player;
 
     private void OnTriggerEnter(Collider other)
     {
         if (other.gameObject == Player)
         {
             Debug.Log("touch");
             Player.transform.parent.parent = transform;
 
         }
     }
 
     private void OnTriggerExit(Collider other)
     {
         if (other.gameObject == Player)
         {
             Player.transform.parent.parent = null;
             Player.transform.localScale = DefaultScale.defaultScale;
         }
     }
     
 }

On Player.transform.parent you need to put another .parent, so the code look like Player.transform.parent.parent

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 QPUNeptune · Mar 07, 2020 at 06:41 PM 0
Share

i'm yeeting myself into the void now

avatar image SylvaxNova04 · Feb 05 at 08:53 PM 0
Share

This has been very helpful, thanks!

avatar image
0

Answer by Magso · Feb 24, 2020 at 10:08 PM

The parent's scale influences the children as well. When it is parented, divide the player's scale by the platform's scale.

For example, if player is scaled (1,1,1) and the platform is (0.7, 0.2, 0.7) the player will need to be scaled to (1.4286, 5, 1.4286) to keep it's correct size when parented. Of course when it is unparented, revert the scale back.

Comment
Add comment · Show 23 · 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 ultimate1999 · Feb 28, 2020 at 09:00 PM 0
Share

Hello $$anonymous$$agso,Thanks for your respond..but i have a little problem ...the problem i have is that i have a big platform i divide the scale of my player with the platform ,it results to a very small player which i cant use because i need my player big.... PLEASE CAN YOU HELP $$anonymous$$E WITH ANOTTHER SOLUTION BECAUSE I COULDNT TRY THIS ONE BECAUSE IT DOESNT FIT $$anonymous$$Y WOR$$anonymous$$...PLEASE I WOULD REALLY APPRECIATE IT ..THIS PROBLE$$anonymous$$ HAS BEING GIVING HEADACHE AND PISSING $$anonymous$$E OFF..PLEASE HELP $$anonymous$$E

avatar image wpatel ultimate1999 · Feb 28, 2020 at 09:57 PM 0
Share

It might be easier if you have one gameObject called PlayerPlatformGroup which has two children, the Player and the Platform. $$anonymous$$ove the entire group but only scale the Platform. You may run into issues if the platform shrinks and the player is no longer on it, but it may be easier to handle than keeping track of the sizes.

avatar image Magso ultimate1999 · Feb 28, 2020 at 11:15 PM 1
Share

The other solution is to scale all physics related GameObjects with colliders, rigidbodies, etc to (1,1,1) and have meshes and all visuals as children.

Another solution is to use a raycast going straight down and OnCollisionEnter. If OnCollisionEnter collision.gameObject and hit.collider.gameObject return the same, get the position and rotation offset when the player lands and follow that GameObject.

 GameObject platform;
 Vector3[] offset;
 
 void Update()
     {
     if(platform)
         {
         transform.position = platform.position + offset[0];
         transform.eulerAngles = platform.eulerAngles + offset[1];
         }
     }
 
 void OnCollisionEnter(Collision collision)
     {
     if (Physics.Raycast(transform.position, Vector3.down, out hit, (size of player / 2)))
          {
              if(hit.collider.gameObject == collision.gameObject)
                  {
                  platform = collision.gameObject;
                  offset[0] = transform.position - collision.transform.position;
                  offset[1] = transform.eulerAngles - collision.transform.eulerAngles;
                  }
           }
     }


avatar image ultimate1999 Magso · Feb 29, 2020 at 12:44 AM 0
Share

HELLO magso..thank you very much for your answer..i really appreciate...i will try it and see if it works..but on question ..where would i add this code?..is it with the platform or the player...thank you once again

Show more comments

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

214 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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 can I move the character like 2D games? 1 Answer

is there any better way to move the character than rigidbody.addRelativeForce? 1 Answer

How to switch between different characters in real time? 0 Answers

Crouch in FPS changes player scale not controller height 1 Answer

In Game player message - GUIText or something else? 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