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 AsPhAlT · Jun 01, 2015 at 01:11 PM · scripting problemmovementplayerobject

manipulating position.y in unity

Hello, i'm trying to create script that will push player to the sky and if it reach equal lvl, it will fall down.

Here's part of code

 if (controller.isGrounded) {//if controller is on the ground
             isFlying=false;//set that it is not flying
 
             if (Input.GetButton ("Jump"))//if button jump
             {    
                 isFlying=true;//the thing started to be in air
                 jumpReached = false;//but it doesnt reach the max altitude
                 jumpStarted=false;//the jump mechanism is not started yet
 }
 
         }
         if (isFlying == true && jumpReached==false && jumpStarted ==false) {//if thing is flying, the altitude is not reached and jump procedure is not started
             moveDirection.y += 0.9F;//set object 0,9 above ground block
             maxJump = moveDirection.y + 10F;//set altitude 10 blocks above ground
             jumpStarted = true;//initial jump procedure ended
         }
         else if(isFlying==true && jumpReached==false && jumpStarted ==true)//if thing is flying, altitude is not reached and jump has started
         {
         if (moveDirection.y >= maxJump)//if altitude reached
                 {
                 jumpReached = true;//now its time to fall down
                 maxJump = maxJump - 10F;//refreshing maxjump 
                 }
             moveDirection.y += 3F;//if not give the player strength to fly to the air ;)
         }
 if (isFlying==true && jumpReached==true) {//if player is in the air and it should fall down
             {
             moveDirection.y -= 0.95F;//decrease player position by 0.95
             controller.Move (moveDirection * Time.deltaTime);
             }
             if(controller.isGrounded == true)//if player is on the ground
                 {
                 isFlying =false;
                 jumpReached = false;
                 jumpStarted=false;
                 maxJump = 0;
                 }//reset everything
         }
         moveDirection.y -= 0.60F;//if nothing happens players is going to fall
         controller.Move (moveDirection * Time.deltaTime);

The problem is that I can't compare position of player to maxJump. Any idea?

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 NoseKills · Jun 01, 2015 at 03:42 PM 0
Share

You should probably move the comments on top of the rows they comment. The code is very hard to read like this.

The problem is that I can't compare position of player to maxJump.

Why ? What happens when you try to? Do you get an error or does the code not work as you expect it to ?

avatar image AsPhAlT · Jun 01, 2015 at 04:19 PM 0
Share
  if (moveDirection.y >= maxJump)//if altitude reached
          {
          jumpReached = true;//now its time to fall down
          maxJump = maxJump - 10F;//refreshing maxjump 
          }

it never starts

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by AsPhAlT · Jun 01, 2015 at 04:34 PM

Ok, done. I just create two transform value; one actual position of object and second - where is the limit. Secondly I used sqrMagnitude, and when the objects are too close it is going to fall.

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 Vice_Versa · Jun 01, 2015 at 03:58 PM

asuming thi script is attached to your player, use transform.position.y tyo refer to its height not moveDirection.y

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 AsPhAlT · Jun 01, 2015 at 04:31 PM 0
Share

Assets/Standard Assets/Characters/ThirdPersonCharacter/Scripts/movement.cs(146,45): error CS0120: An object reference is required to access non-static member `UnityEngine.Transform.position'

I miss something?

avatar image Vice_Versa · Jun 01, 2015 at 10:21 PM 0
Share

transform is spelled with a lowercase t. monodevelop autocorrects it for no particular reason

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How can I make the EnemyBullet go further than my target? 0 Answers

My player ball is shaking when it changes position 1 Answer

My player doesn't turn based on the mouse when it's supposed to 0 Answers

Fuel bar doesn't work! 1 Answer

Rotating a player object without rotating the axis 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