Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 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 /
  • Help Room /
avatar image
0
Question by apex1911 · Feb 05, 2020 at 03:29 PM · positionscalecoordinatesy axis

How to make my Player smaller if he moves the y coordinate up?

Hey, im making a point and click game with 2d pictures. I want to make my player smaller when he goes up the picture (or y coordinate) to create a realistic feeling where it feels like the player is moving away from the camera.

im pretty new to scripting so i dont really have a clue.. but i thought about something like when the y coordinate of the player is increasing the y.scale should decrease but i dont know how to realize it?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by tormentoarmagedoom · Feb 05, 2020 at 03:47 PM

Hello there.

Then you should create a function inside the update (so its exected every frame) wich controls the scale of the sprite.

You should find the relation between the y position and the scale. For start, you need to know the transform.position.Y coord (I supose is Y coord but if you rotated the camera can be any other comoponent) of your character. Lets say, the Y value can go from +50 (top of map) to -50 (botom of map). And when is at top you want the sprite to be 125% of its original size, and when its at bottom, at 75% of original size. Then assign a multiplier to the scale of the sprite, (Scale is a property of the Transform component of any object).

Some code like This:

 void Update()
 {
 
 // Original Scale is always 1
 // Scale is a vector, so you need to change all its components to mantain the aspect ratio)

 int ScaleValue = 1-(TheSpriteObject.tranform.position.y/200);

 TheCharacterObject.transform.scale =  new Vector3 ( ScaleValue , ScaleValue , ScaleValue );
 }

So each frame will be calculating the scale of the character.

This way, when position.y is -50 scale will be 1.25 (125%).

When position is +50, scale will be 0.75 (75%).

You need to find your way to get what you need. This is not about knowing commands or functions. Is about thinking.

Good Luck! Bye!"

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 apex1911 · Feb 05, 2020 at 04:00 PM 0
Share

thank you for your fast answer and your help! im getting it now, but i still have some questions: whats the difference between the SpriteObject and the CharacterObject? I mean my CharacterObject is my player but whats the SpriteObject? The Background? And if im trying to use the .scale it says theres only localScale, is this the same?

avatar image channelforprose · May 15, 2021 at 09:27 PM 0
Share

@tormentoarmagedoom So this is exactly what I've been looking for, but sadly I'm still a novice. I've been binging C# tutorials just so I can figure out how to add your script to a 2D game but I still can't wrap my head around how to do it. I understand where to add within the Update function but beyond that, I'm struggling with what fields I should be adding my size values to and what the language would be. My best guess is that "TheCharacterObject" would be the PlayerController for my project and theSpriteObject would then be the sprite used by that object but then that leaves me with errors in the console? Could I please bug you to elaborate further for a beginner?

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

219 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Instantiate creates object at wrong position 4 Answers

Getting position of a coordinate on the surface of a sphere 0 Answers

Player Floating 0 Answers

Can you help explain this positioning conundrum to me! 1 Answer

Organising children in the local position is out of place. 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