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 /
  • Help Room /
avatar image
0
Question by Civil-Anarchy · Jan 11, 2016 at 03:45 PM · scripting problemmovementphysicsvector3character

Can I ignore part of a vector3 for physics reasons?

Hi! Long time reader, first time asker.

I'm coding my own 3rd person character controller that pivots around and object and has a set velocity (for a 1v1 Arena fighter) - so of course when I set a velocity for this 3D character I need a Vector3.

Currently, my velocity is set to be clamped as well as follows: me.velocity = Vector3.ClampMagnitude (move, speed ) * Time.deltaTime ;

the problem with that being that the Y value of the move vector is 0, and calls for 0 on every fixed update, which has made figuring out how to jump very difficult.

If I change it to me.velocity += Vector3.ClampMagnitude (move, speed ) * Time.deltaTime ;

I can easily make a nice jumping motion, but my ground movement becomes very fast and sliding, not the snappy movement I want, and have to move a lot of other code around.

This entire controller was initially coded through transformations, but I realized I needed to use physics based movement because there's a lot of collision involved.

It's entirely possible that the solution is simple and that I've been banging my head against it too long to see it, but is there any way to straight up ignore the 0 Y value being set through that vector so that gravity behaves normally, or is there a way to apply velocity in an additive, but not cumulative way (so it acts as if I just set the velocity... I guess without actually setting it?)

the following is all the code from the relevant area of the script:

 Vector3 forward = cameraTransform.TransformDirection(Vector3.forward);
         forward.y = 0f;
         forward = forward.normalized;
         Vector3 right = new Vector3(forward.z, me.velocity.y - Physics.gravity.y, -forward.x);
         float h = Input.GetAxis ("Horizontal");
         float v = Input.GetAxis ("Vertical");
         Vector3 walkDirection = (h * right + v * forward);
 
         float movex = walkDirection.x * speed;
         float movez = walkDirection.z * speed;
         Vector3 move = new Vector3 (movex, 0, movez);
         me.velocity = Vector3.ClampMagnitude (move, speed ) * Time.deltaTime ;
 
 
         me.velocity += new Vector3 (0, me.velocity.y + gravforce  , 0) * Time.deltaTime ;
 
         if (Input.GetKey (KeyCode.Joystick1Button0) && isgrounded ) {
             me.AddForce (Vector3.up * force);
             isgrounded = false;}
         if (isgrounded == false) {
             speed = 200f;
 
         }else if (isgrounded == true){
             speed = defaultspeed;
             force = defaultforce;
         }

thanks so much for potential answers!

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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Unity2D Help with rigidbody character movement. 0 Answers

New Vector2 won't take effect when called from another script in the same GameObject. 0 Answers

how to dostraight ball throwing objects from returning? 0 Answers

I am interested in moving a ragdoll character only using Forces. 0 Answers

How to move whilst airborne (using standard third person character script)? 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