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
1
Question by KINDOK · Jun 03, 2016 at 01:28 PM · c#scripting problemsmoothcrouch

Correctly smooth crouch script?

In all internet, there isn't any crouch script that work correctly without mistakes like this: -On crouch/uncrouch the player fall down of the map. -When uncrouch, player go through the ceiling. -Smooth crouch/uncrouch.

It's too hard do this? For me, yes; because I'm a beginner programmer. But for a advanced programmer this must be a easy task (maybe).

A tutorial teaching it would be famous. Why anybody do this?

I only found two styles of videos: -The tutorial with full errors. -The video that show to you his work (a perfect and great work) but without showing his script or how it has done.

I take the opportunity to ask the following: Somebody know any tutorial series that teach you advanced programming in c#? To do scripts like this.

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

2 Replies

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

Answer by Zodiarc · Jun 03, 2016 at 02:09 PM

Look for BurgZergArcade on youtube. He has a huge tutorial series on unity and c#.

But to your actual problem:

I can't think about the falling through the worid without looking at the script but you can prevent the clipping through the ceiling by doing a raycast upwards every time the player tries to stand up. If the raycast hits the ceiling that means there's not enough room for him to stand up and you simply don't execute the stand up step.

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 KINDOK · Jun 03, 2016 at 02:14 PM 0
Share

Thanks for your reply and the yt channel.

avatar image KINDOK · Jun 03, 2016 at 04:16 PM 0
Share

This is my actually script. The main problem now is that the player uncrouch and through ceilings. How I would do the raycast that you said?

 using UnityEngine;
 using System.Collections;
 using UnityStandardAssets.Characters.FirstPerson;
 
 public class Crouch_func : $$anonymous$$onoBehaviour {
 
     // PUBLIC VARS //
 
     public Transform t_mesh;                    // Player Transform
     public CharacterController ccr_controller;  // Get the character controller
     public bool IsCrouch = false;               // 
     public float LocalScaleY;                   // Y scale of "t_mesh"
     public float ControllerHeight;              // Y scale of the character controller
 
     // PRIVATE VARS //
 
     void Start()
     {
         //nothing here yet
     }
 
     void Update()
     {
         if(Input.GetButtonDown("Crouch"))
         {
             IsCrouch = !IsCrouch;
             CrouchFunction();
         }
     }
 
     void CrouchFunction()
     {
         if(IsCrouch == true)
         {
             t_mesh.localScale = new Vector3(1, LocalScaleY, 1);
             ccr_controller.height = ControllerHeight;
             Debug.Log("c_func 1");
         }
         else
         {
             t_mesh.localScale = new Vector3(1, 1, 1);
             ccr_controller.height = 1.8f;
             Debug.Log("c_func 0");
         }
     }
 }
 
avatar image Zodiarc KINDOK · Jun 06, 2016 at 06:36 AM 1
Share

Should look something like this:

 void CrouchFunction()
      {
          if(IsCrouch == true)
          {
              t_mesh.localScale = new Vector3(1, LocalScaleY, 1);
              ccr_controller.height = ControllerHeight;
              Debug.Log("c_func 1");
          }
          else
          {
              Ray ray;
              RaycastHit hit;
              ray.origin = transform.position;
              ray.direction = transform.position.up;
              if(!Physics.Raycast(ray, out hit, 1)){
                  t_mesh.localScale = new Vector3(1, 1, 1);
                  ccr_controller.height = 1.8f;
                  Debug.Log("c_func 0");
              } else {
                  Debug.Log("Not enough space to stand up!);
              }
          }
      }
avatar image KINDOK Zodiarc · Jun 06, 2016 at 10:43 AM 0
Share

I get an error with this line: ray.direction = transform.position.up;

It underline in red the transform.position.up Upon returning to the editor I have two errors: alt text I've searched info about this error but nothing help me. I must to create a static var? Thanks a lot.

error.png (11.4 kB)
Show more comments
avatar image KINDOK · Jun 06, 2016 at 11:51 AM 0
Share

@Zodiarc Wow thanks!! It work perfect! :D

avatar image
1

Answer by NateLaw1988 · Aug 19, 2019 at 01:43 PM

Hi I know this is an old post but incase someone new comes along like I did I have posted a video with a project download link to a heavily extended first person controller

https://www.youtube.com/watch?v=NLe9QOw05kM&t=13s

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

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

Related Questions

SmoothDamp bug? 0 Answers

When I run this code Unity crashes(ANIMATOR RELATED) 0 Answers

What am i doing wrong with my jump attack ? 0 Answers

How to use IF statement ONLY when a certain gameobject is in the scene? 1 Answer

money system in c# 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