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 /
avatar image
0
Question by ben0bi · May 26, 2011 at 09:25 AM · movementgravityvector

Movement vector does not take the gravity vector..

I am trying to make a game where the gravity can switch in some areas.

I use two vectors for this: GravityDown wich drags the player down and GravityRight wich indicates in wich direction the player will run.

If i change this vectors, they will be changed in the inspector but the code will take the old values.

It will also not run if i create new vectors..

Code:

 var GravityDown : Vector3 = new Vector3(0,-1,0);
 var GravityRight: Vector3=new Vector3(0,0,1);

 function Update()
 {
 // change local gravity
 if(Input.GetButton("Fire2")
 {
   GravityDown=new Vector3(0,0,1); // gravity drags to the right
   GravityRight=new Vector3(0,1,0); // player runs up, down
 }

 forwardMovement = GravityRight*(Right-Left)  * Time.deltaTime * MovementSpeed;
 print("GravityRight:"+GravityRight.x+GravityRight.y+GravityRight.z);
 forwardMovement+=GravityDown*airMultiplier;

 transform.position+=forwardMovement;
 }

it will show the right variables in the print but it will drag the player on the same way ever...

what can i do here?

Comment
Add comment · Show 1
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 Bunny83 · May 26, 2011 at 10:17 AM 0
Share

print("GravityRight:" + GravityRight); should be enough. It's nicer formatted.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · May 26, 2011 at 10:15 AM

If you press Fire2 you set the "GravityRight" vector to point to the right (World space). What change do you expect? where do you change the vector? And most important what is "Right" and "Left". Is it a 3D game? I just wonder why you move the right(x-axis)?

edit
Just saw you don't use "right(x-axis)" you use forward (z-axis). Why do you call it right?

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 ben0bi · May 26, 2011 at 10:39 AM

The change wich i would expect is that the player moves to the right by gravity, but all he does is moving to the ground like before. If fire2 was pressed, the player should move up and down and gravity should drag towards right. Before fire2 is pressed, gravity drags down and the player moves right/left.

  • its a 2d sidescroller jumpnrun.

  • i removed rigidbody/collisionbox/charactercontroller to make it move without physics and stuff.

  • I also removed all "real physics" gravity stuff..

  • Right and Left can be 1 or 0 each, so Right-Left can be between -1 and 1

  • all the stuff is in the players update function

answer to the edit: the game level is aligned on the z axis and its 2d sidescrolling so right and left are z+ and z- from camera view point.

Comment
Add comment · Show 1 · 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 Bunny83 · May 26, 2011 at 11:08 AM 0
Share

You should edit your question ins$$anonymous$$d of posting an answer ;) or use comments.
I don't see any problem with that script. As long as GravityRight (which should be called something like movementDirection) is changed it should work. Are you sure you don't reset it somewhere else? $$anonymous$$aybe from another script? You can print the forward$$anonymous$$ovement variable to see if it's right.

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

2 People are following this question.

avatar image avatar image

Related Questions

How do I control the Max Fall Speed of the First Person Controller? 0 Answers

translate 2 Answers

How to set and objects gravity direction to Z -10 based on the objects rotation? (2D) 1 Answer

toss up game object into air with freefall physics 1 Answer

Need very specific help with Quaternions 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