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 Gigen · Aug 09, 2013 at 06:40 AM · movementrigidbodymovement scriptaddrelativeforce

Making rigidbody force movement snappy

I am making a platformer but I want the player character to have a rigidbody so he can correctly collide with other rigidbody objects in the game world.

After transform.Translating the character box (just a placeholder gameObject) I saw that was not the way to go and started AddingRelativeForce to the character (for movement AND for jumping).

However, I ran into multiple issues:

  • The movement starts off sluggishly

  • The character jump is not snappy and responsive, but looks and feels as though he were a rocket that's slowly lifting up

  • After the character finally picks up speed he quickly becomes uncontrollably fast

How can I achieve a responsive and accurate movement of my rigidbody character? I want the game to feel like Super Mario Bros and not like Little Big Planet (both great games, mind you). Thanks.

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 AdenFlorian · Aug 19, 2013 at 08:56 PM 1
Share

Have you looked into using a CharacterController? Just had to make sure you considered that first.

Adding force to an object over time (in FixedUpdate()) will continuously increase the object's velocity until you stop adding force.

You could add force once on move button down, then add the negative value of that force once when the movement button is lifted up. Add force once to start movement, the add then negative force once to stop movement (in that direction).

Same for jumping. Add a force once to propel it upwards, and then it will fall back down. It will jump higher or lower depending on the amount of initial force used.

When using this method with AddRelativeForce (or AddForce), make sure the Force$$anonymous$$ode is set to Impulse.

4 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by 2d4Games · Aug 19, 2013 at 08:49 PM

rigidbody.addForce and addRelativeForce are acceleration modifiers, that slowly increase speed. What you want to do is set rigidbody.velocity to a value, as that will produce instant movement and it won't be sluggish or speed up unexpectedly. Also, when setting the velocity vector, remember to have a scalar multiplier on it so you can easily control the speed.

Something like:

 var speed = 10; //This is a multiplier that you can easily tweek in unity.
 
 rigibody.velocity = Vector3(0,1,0) * speed; //multiply the direction by an appropriate speed, Vector3(0,1,0) is straight up.
 
 
Comment
Add comment · Show 7 · 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 orbitopus · Aug 19, 2013 at 08:58 PM 0
Share

can you use velocity in such a way that it is relative to the rigid body?

avatar image AdenFlorian · Aug 19, 2013 at 09:01 PM 0
Share

Take the transform.forward vector (which is normalized) and multiply it by a scalar (what you want the velocity to be in that direction, i.e. the direction the object is facing, the forward z+ direction)

avatar image Gigen · Aug 19, 2013 at 09:18 PM 0
Share

Thanks for the answers so far. Your solutions work perfectly but I should have given you more info to see why they do not apply to my particular issue.

The characters in my game have Jedi-like force push abilities (this could be anything, from AddExplosionForce to the new particle collision callback implementation) and I want them to be able to push each other. If I set velocity and/or position directly weird things start happening (for example on a horizontal push all energy gets transferred to Y axis and they fly straight up).

I tried using AddForce but the implementation I found increased drag which was proportionate to character vector magnitude. This worked fine as well but the drag was largest when there was no input (to prevent the character from sliding around when you released the analog stick) which meant the character could not jump because of too much drag.

avatar image AdenFlorian · Aug 19, 2013 at 09:27 PM 0
Share

Changing the position and changing a rigid body's velocity are not the same. You shouldn't manipulate the position of a rigid body directly, or you will get unexpected results, because you are cheating the physics engine.

I'm not sure why changing the rigidbody.velocity is giving you unexpected results. I should mention the using AddForce with Impulse as the Force$$anonymous$$ode essentially does the same thing as changing the velocity directly, except your input is a force ins$$anonymous$$d. $$anonymous$$ight be worth to try that out if you haven't yet. All depends on how you are deter$$anonymous$$ing the movement of your characters which would be easier or make more sense.

avatar image Gigen · Aug 19, 2013 at 09:45 PM 0
Share

Okay, would this be the correct way of handling rigidbody movement for my case?

transform.rigidbody.velocity = new Vector3(movementDirection.x * movementSpeed, transform.rigidbody.velocity.y, 0);

Show more comments
avatar image
3

Answer by Baintastic · Nov 25, 2015 at 12:18 PM

Editing your velocity directly works great if there are never any external forces in your game. Otherwise, set the drag in your rigidbody and use:

 rigidbody.AddForce(force, ForceMode.VelocityChange);
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
2

Answer by scipiothegreat · Aug 20, 2013 at 01:24 AM

The best way to handle is this is to use

 rigidbody.AddForce(force, ForceMode.Impulse);

The default ForceMode is ForceMode.Force which applies a certain amount of force over the space of a second. ForceMode.Impulse applies the same amount of force in one physics frame.

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 Gigen · Aug 20, 2013 at 06:43 AM 1
Share

I am already using this for the jump and it works okay. What about sideways movement?

avatar image scipiothegreat · Aug 20, 2013 at 06:32 PM 0
Share

There is also Force$$anonymous$$ode.Accerlerate which increases the rigidbody's velocity without regards to the mass.

avatar image
0

Answer by orbitopus · Aug 19, 2013 at 08:55 PM

I'm new to unity and am working on similar physics movement and came across something that might help

for snappy jumping you can use Rigidbody.velocity to add a burst speed in a direction

  if (Input.GetKeyDown("Jump")){
     rigidbody.velocity = Vector3(0,10,0);
     }

let me know if you came up with a solution to any of your other problems. :)

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 Gigen · Aug 19, 2013 at 09:19 PM 0
Share

This one works fine (I just tested it) but I am afraid it does not apply to my particular case. Check my bottom comment if you wish :).

I will be sure to inform you if I find a solution to my problem

avatar image Gigen · Aug 19, 2013 at 09:26 PM 0
Share

Okay, this series of videos looks quite promising: https://www.youtube.com/watch?v=GddQmaFLZ00&list=PL7AE076AFAFD3C305

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

20 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 avatar image avatar image

Related Questions

How do I stop unwanted rotations? 4 Answers

How to move Character with AddForce 1 Answer

How to make a rigidbody move in the direction of finger(x,y,z) 1 Answer

Why does my character keep sliding around? Help! (Rigid Body) 1 Answer

(C#) Movement Rotation Script not Working! 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