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 Borzi · Sep 24, 2013 at 06:00 PM · rigidbodyjumpwalk

Player walking Script

Hey guys! Some of you might now the ETeeski tutorials, some of you might not. Either way, this is a script from one of his tutorials and I have one small issue: The player wont move from the spot (or jump). I copied the script from his tutorials, which didn't work out for me, and then copy pasted his reference script, still no difference. Can anybody figure out what I might be doing wrong? Here's the script I have for reference. Thank you in advance!

 var walkAcceleration : float = 5;
 
 var walkAccelAirRacio : float = 0.1;
 
 var walkDeacceleration : float = 5;
 
 @HideInInspector
 
 var walkDeaccelerationVolx : float;
 
 @HideInInspector
 
 var walkDeaccelerationVolz : float;
 
  
 
 var cameraObject : GameObject;
 
 var maxWalkSpeed : float = 20;
 
 @HideInInspector
 
 var horizontalMovement : Vector2;
 
  
 
 var jumpVelocity : float = 20;
 
 
 var grounded : boolean = false;
 
 var maxSlope : float = 60;
 
  
 
 function LateUpdate () 
 
 {
 
     horizontalMovement = Vector2(rigidbody.velocity.x, rigidbody.velocity.z);
 
     if (horizontalMovement.magnitude > maxWalkSpeed)
 
     {
 
         horizontalMovement = horizontalMovement.normalized;
 
         horizontalMovement *= maxWalkSpeed;     
 
     }
 
     rigidbody.velocity.x = horizontalMovement.x;
 
     rigidbody.velocity.z = horizontalMovement.y;
 
     
 
     if (grounded)
         {
         //Get the Player to slowly gain speed
         rigidbody.velocity.x = Mathf.SmoothDamp(rigidbody.velocity.x, 0, walkDeaccelerationVolx, walkDeacceleration);
 
         rigidbody.velocity.z = Mathf.SmoothDamp(rigidbody.velocity.z, 0, walkDeaccelerationVolz, walkDeacceleration);
         }
 
     
     //Player faces the direction of the Camera
     transform.rotation = Quaternion.Euler(0, cameraObject.GetComponent(MouseLookScript).currentYRotation, 0);
 
     
 
     if (grounded)
         //Player moves in directions in case the user presses "wasd" buttons if player is grounded
         rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * walkAcceleration * Time.deltaTime, 0, Input.GetAxis("Vertical") * walkAcceleration * Time.deltaTime);
 
     else
         //If the player isnt grounded use the vars for his air control
         rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * walkAcceleration * walkAccelAirRacio * Time.deltaTime, 0, Input.GetAxis("Vertical") * walkAcceleration * walkAccelAirRacio * Time.deltaTime);
 
             
 
     if (Input.GetButtonDown("Jump") && grounded)
         //If player jumps, add force to the rigid body
         rigidbody.AddForce(0,jumpVelocity,0);
 
 }
 
  
 
 function OnCollisionStay (collision : Collision)
 
 {
 
     for (var contact : ContactPoint in collision.contacts)
 
     {
 
         if (Vector3.Angle(contact.normal, Vector3.up) < maxSlope)
 
             grounded = true;
 
     }
 
 }
 
  
 
 function OnCollisionExit ()
 
 {
 
     grounded = false;
 
 }
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 Borzi · Sep 25, 2013 at 03:05 PM 0
Share

Still no ideas anyone?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Sep 25, 2013 at 05:35 PM

@Borzi - you can delete your question again if you like. I just got done taking a look at your code. You can get it to work by 1) adding a physic low friction physic material (like ice) to the colliders of your character and the surface. And 2, reducing the mass of your player to around 0.05. The problem I see is that the amount of force being applied is too small for the friction and mass.

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.

Follow this Question

Answers Answers and Comments

15 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

Related Questions

Jump Input Sensitivity 0 Answers

How do I make my character jump over a cube with rigid body moving towards it 1 Answer

rigidbody.AddForce jump, different heights each time 1 Answer

my jump every 3 seconds program is not working 3 Answers

Setting Rigidbody Velocity for Jump Unity 5 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