• 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 ngotm_tn · Jun 12, 2015 at 08:43 PM · vector3movement scriptjumpingnormalized

Making jumping independent of normalized movement?

I've just gotten started with Unity, and I've been working on some basic 3D first-person controls and movement. The problem I've been struggling with is how to incorporate jumping without the y vector being counted as part of the final normalized movement vector. In other words, how can I keep an accurate diagonal speed without jumping having an effect?

I want to be able to jump while traveling in any direction on the x-z plane without my horizontal speed changing.

A stripped down version of my script with the general ideas:

 float forwardSpeed = Input.GetAxisRaw ("Vertical") * speed;
 float strafeSpeed = Input.GetAxisRaw ("Horizontal") * speed;
 
 Vector3 movement = new Vector3(strafeSpeed, 0, forwardSpeed);

 if (Input.GetButton ("Jump")) {
     movement.y = jumpSpeed;
 }
         
 Player.Move (movement.normalized * Time.deltaTime);



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
0

Answer by FortisVenaliter · Jun 12, 2015 at 08:45 PM

You could just actually handle them separately. For example:

 Vector3 horizontal = new Vector3(src.x, 0, src.z);
 Vector3 vertical = new Vector3(0, src.y, 0);
 
 Vector3 final = horizontal.normalized + vertical;
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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

How to Make Velocity.y based on AddForce 0 Answers

Roll a ball to fixed distance 3 Answers

rigidbody.velocity.normalized application 1 Answer

Vector3 values always precalculated, or just in MonoDevelop? 1 Answer

Jumping problem to do with /= magnitude changing the vector3 direction 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges