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 GrKl · Sep 12, 2013 at 04:13 PM · c#movementjumpside

have 3rd person make a side jump

Hi All,

I am trying to make my player side jump since a few days. For the normal jump I use the classic:

 if (Input.GetButtonDown("Jump"))
             rigidbody.velocity = new Vector3(0, 10, 0);

but I cant find any way to have him jump and move side ways (left or right)

I tried affecting Velocity, AddForce, AddRelativeForce,... using Vector3.right, (float x, float y, float z),... but whatever I try, he never moves side ways with those.

If any of you would have a hint on how to do this, it would greatly help me.

Thanks

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
2
Best Answer

Answer by vexe · Sep 12, 2013 at 04:35 PM

I assume that you're not using the standard character controller to learn and implement everything on your own. Check out this series from Quilly where he makes a character controller from scratch, he covers a lot of things in really great detail, I'm sure you will resolve your problem there. Helped me a lot, hope it does the same for you :)

EDIT: OK so well Quilly didn't cut it for you, that's why we're here :)

It was easier than I thought, I did it with a rigidbody attached to my player, it worked really nice for me. Here you go:

 // This enum is for convenience, you can go without it if you want, I like to stay organized :)
 public enum DodgeDirection { Right, Left, Forward, Backward }

 // This vector is essential if you want to have variants dodging amounts/forces, it represents how much the player will go to the side, up and forward
 // left: -x, right: +x, up: +y, down: -y, forward: +z, backward: -z. Don't worry you'll understand in a moment
 // if you don't want to have different forces applied to your player when he dodges left/right, forward/backward, just get rid of this vector and use a float variable instead
 public Vector3 dodge = new Vector3(5, 5, 5);

 // This is the dodging method, you just give it a direction and it will handle the rest using the `dodge` vector we previously defined.
 public void Dodge(DodgeDirection dir)
 {
         switch (dir) 
         {
             case DodgeDirection.Right:
                 rigidbody.AddForce(_transform.right * dodge.x + _transform.up * dodge.y, ForceMode.Impulse);
                 break;
             case DodgeDirection.Left:
                 rigidbody.AddForce(-_transform.right * dodge.x + _transform.up * dodge.y, ForceMode.Impulse);
                 break;
             case DodgeDirection.Forward:
                 rigidbody.AddForce(_transform.forward * dodge.z + _transform.up * dodge.y, ForceMode.Impulse);
                 break;
             case DodgeDirection.Backward:
                 rigidbody.AddForce(-_transform.forward * dodge.z + _transform.up * dodge.y, ForceMode.Impulse);
                 break;
         }
 }

 // Since we're gonna be dealing with a rigidbody and forces, we might as well use FixedUpdate
 // I used 'l', 'j', 'i' and 'k' to dodge left, right, forward and backward (respectively)
 // If I were you and using WASD controls, I would dodge left by double tapping 'A', right by double tapping 'D' etc. (With a threshold I define)
 void FixedUpdate()
 {
     if (Input.GetKeyDown("l"))
             Dodge(DodgeDirection.Right, dodge);
     if (Input.GetKeyDown("j"))
             Dodge(DodgeDirection.Left, dodge);
     if (Input.GetKeyDown("i"))
             Dodge(DodgeDirection.Forward, dodge);
     if (Input.GetKeyDown("k"))
             Dodge(DodgeDirection.Backward, dodge);
 }
 

Couple of notes:

  1. In my test environment, I was using a capsule collider for my player so I had to constrain all the rotations in the rigidbody component, because since I'm adding force, the capsule would get knocked out and thrown to the ground (kinda cool effect if you want fighting in your game) - So no rotation from the rigidbody, I handled rotation myself.

  2. I tried all the possible types of forces, only Impulse and VelocityChange seemed to do the trick, while Force and Acceleration didn't seem to have any effect.

  3. Wondering about _transform? - I always like to cache my transform component if I'm gonna be using it a lot, because when you do transform, you're actually calling GetComponent<Transform>() - which isn't nice to call so many times. (I usually cache in Start or Awake)

  4. Make sure you handle the rotation of your player well, let me know if you have trouble with that - You could use Quilly's code for that, works like charm.

Let me know how it goes, hope I helped :)

Comment
Add comment · Show 6 · 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 GrKl · Sep 12, 2013 at 06:07 PM 0
Share

thanks, I'll definitly check it out! Indeed, beeing new in coding & in unity, I find it much more interesting to code everything from scratch than to take premade scripts

avatar image GrKl · Sep 12, 2013 at 09:03 PM 0
Share

ok, just 'eated' all of those videos already! but I'm afraid it didnt answer my question. Would any one have an idea on how to implement this?

avatar image vexe · Sep 13, 2013 at 03:19 AM 0
Share

What do you mean? - with Quilly's character controller, you can't jump the way you want? - why don't you just jump and go side ways? - or that's not how you want it. You wanna be able to press like 'd' and then space, and your character would make a jump just to the right? is that what you want?

avatar image GrKl · Sep 13, 2013 at 08:55 AM 0
Share

Actually, my goal would be to make a dodge movement.

I have no problem with the normal Jump and basic movements.

indeed your last sentence explains kind of what I need.

if player press jump + side (left or right) he would make a similar jump action with an additional side movement. $$anonymous$$y problem is that I cant use translate as I would like to make this dodge with a mouse click+side button. Once these buttons are pressed, this movement should go untill the end of this move, event if the buttons are released. but translate would only work during the click is done, and click is done just 'during' one frame

I'm sorry if I wasn't clear enough before (English is not my natural language)

avatar image GrKl · Sep 13, 2013 at 09:09 PM 0
Share

Thanks alot! some verry interesting triks (for example _transfrom that i've read elsewhere, but did not understood the advantage before)

before 'simply' copying your hole code, and to test it (not that I dont trust you ;-) ) I just tried with:

if (Input.Get$$anonymous$$ouseButtonDown(2)){ rigidbody.AddForce(transform.right 8 + transform.up 8 , Force$$anonymous$$ode.Impulse);}

nothing else was changed to my code

But I actually get the same result I did before posting this question; only y movement is applied but the .right movement is not affected

realtime EDIT: Oh my god... I feal incredibly ashamed! I frozed my rigidBody X & Z Position some time ago... unticked it; tested... SOLVED...

I was using this to prevent my player sliding down hills if Idle. Guess I'll have to code that.

So from the beggining, I tried lots of code and forgot completely about that! Though I still thought that coding movement overrided that "freeze Poistion"

at least I learned a few verry intersting things, and understood once again to triple check everything!

Hope this discution will still give hints for others that me at least

thanks again for your pressious help

Show more comments

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

18 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

Related Questions

Making a bubble level (not a game but work tool) 1 Answer

Extend simple movement script (C#) 1 Answer

Can't get character to Jump on the Y Axis (C#) 2 Answers

[C#] Jump on slopes 1 Answer

I cant make my character jump ?,Why can't he jump ? 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