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
2
Question by Roncon · Dec 24, 2012 at 05:51 AM · fpsslidecharactermotor

How to do sliding like Crysis and/or FarCry?

Hi there, I am making an FPS and I want to feature a sliding mechanic like Crysis and some other games have where the player presses a button while sprinting and the character slides on the floor. I've already set up sprinting and crouching but I have no idea to do sliding. Any help would be appreciated, also, I am using the default CharacterMotor to move around. Thanks!

Comment
Add comment · Show 4
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 moinchdog · Dec 27, 2012 at 12:10 PM 0
Share
  • on this ive been trying to figure this out for ages

avatar image Lovrenc · Dec 27, 2012 at 12:20 PM 0
Share

If you're using mecanim humanoid there is starter pack on asset store with sliding animations and you could use those.

avatar image moinchdog · Dec 27, 2012 at 01:00 PM 0
Share

im not using mecanim in using a fps character ive built. I dont really $$anonymous$$d about animations i can do that with the camera i just want the sliding

avatar image AlucardJay · Dec 27, 2012 at 01:22 PM 0
Share

You somehow have to tap into the character controller and take over, implement something like a crouch with a run speed for a certain period of time, and disable other inputs for that time, then when the time is reached leave the character controller crouched. Here is a great example on how you can tap into the character controller and modify the variables : http://answers.unity3d.com/questions/164638/how-to-make-the-fps-character-controller-run-and-c.html

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by AlucardJay · Jan 05, 2013 at 04:03 AM

Using the crouch and run script by Aldo (awesome script), I have added sliding. Set slideSpeed and slideTimerMax. When sliding, the player can look around, but not change direction.

 #pragma strict
 
 var walkSpeed: float = 7; // regular speed
 var crchSpeed: float = 3; // crouching speed
 var runSpeed: float = 20; // run speed
 
 private var chMotor: CharacterMotor;
 private var ch: CharacterController;
 private var tr: Transform;
 private var height: float; // initial height
 
 public var slideSpeed: float = 20; // slide speed
 private var isSliding : boolean = false;
 private var slideForward : Vector3; // direction of slide
 private var slideTimer : float = 0.0;
 public var slideTimerMax : float = 2.5; // time while sliding
 
 function Start()
 {
     chMotor = GetComponent(CharacterMotor);
     tr = transform;
     ch = GetComponent(CharacterController);
     height = ch.height;
 }
 
 function Update()
 {
     var h = height;
     var speed = walkSpeed;
     
     // - run and crouch -    
     if (ch.isGrounded && Input.GetKey("left shift") || Input.GetKey("right shift")) // press Shift to run
     {
         speed = runSpeed;
     }
     if (Input.GetKey("c")) // press C to crouch
     {
         h = 0.5 * height;
         speed = crchSpeed; // slow down when crouching
     }    
     
     // - slide -    
     if (Input.GetKeyDown("f") && !isSliding) // press F to slide
     {
         slideTimer = 0.0; // start timer
         isSliding = true;
         slideForward = tr.forward;
     }
     if (isSliding)
     {
         h = 0.5 * height; // height is crouch height
         speed = slideSpeed; // speed is slide speed
         chMotor.movement.velocity = slideForward * speed;
         
         slideTimer += Time.deltaTime;
         if (slideTimer > slideTimerMax)
         {
             isSliding = false;
         }
     }    
     
     // - apply movement modifiers -    
     chMotor.movement.maxForwardSpeed = speed; // set max speed
     var lastHeight = ch.height; // crouch/stand up smoothly 
     ch.height = Mathf.Lerp(ch.height, h, 5 * Time.deltaTime);
     tr.position.y += (ch.height - lastHeight) / 2; // fix vertical position
 }


Comment
Add comment · Show 3 · 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 moinchdog · Jan 05, 2013 at 06:01 AM 0
Share

had a go of this and my character kept falling through the terrain. But its ok ive made my own version using the SetVelocity function of the Character$$anonymous$$otor script.

avatar image AlucardJay · Jan 05, 2013 at 06:25 AM 0
Share

I have seen other questions with people having trouble with the character collider falling through the terrain, I personally have never seen nor had this problem, and after 10 $$anonymous$$utes I am happy to say this is tested and working. Another question came up, so I did an answer : http://answers.unity3d.com/questions/374157/character-controller-slide-action-script.html

Great that you found a way yourself !

avatar image Roncon · Jan 05, 2013 at 04:12 PM 0
Share

Thank you for all your help everyone! I actually found out a way to do it since I didn't think I was going to get this many answers. Although I do want to implement some of the functionality found in alucardj's script. Again, thank you!

avatar image
0

Answer by Maulik2208 · Dec 27, 2012 at 01:15 PM

Why don't you make a trick rotate your player (Gameobject) and add some timer as well as extra force on the sliding (moving) direction.....all i want to say is that spacebar is pressed then player is rotated on some angle suitable to you and the timer starts for undoing rotation and take the player back to the original (standing position) and remove extra applied forces........Hope this idea works for you.....

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

13 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

Related Questions

editing maxforwardspeed in charactermotor via script? help! 1 Answer

Collider not responding to my actions 1 Answer

Player fall away from mountain edge without slide? 0 Answers

How can you make a FPS controller camera "fly"? 1 Answer

FPS Dynamic Speed variables 1 Answer


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