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 /
This question was closed Aug 20, 2017 at 08:57 AM by hexagonius for the following reason:

Unity answers is not about getting scripts fixed, it's about Unity

avatar image
0
Question by arefjoan · Aug 20, 2017 at 08:32 AM · errorphysics

physicWalk.cs

hi can you fix my physicWalk script,when i click play button i just fall down in floor like broken leg and camera keep on floor

using UnityEngine; using System.Collections;

public class physicWalk : MonoBehaviour {

 public static physicWalk instance;
 
 //
 public float speed  = 7f;
 public float maxSprintSpeed = 7f;
 public float maxWalkSpeed = 4f;
 public float force     = 8f;
 public float jumpSpeed = 5f;
  
 public float footsFrequency = 0.7f;

 //
 public bool grounded = false;
 
 private float fallingForce = 0f;
 
 private CapsuleCollider collider;
 
 private bool canJump = true;
 private float canJumpCounter = 0f;

 public AudioClip footstepSound;
 public AudioClip fallSound;

 void Start()
 {
     instance = this;
     
     collider = gameObject.GetComponent< CapsuleCollider >();
 }
 
 // Don't let the Physics Engine rotate this physics object so it doesn't fall over when running
 void Awake ()
 { 
     
     speed = maxWalkSpeed;
 }
 
 public virtual float jump
 {
     get 
     {
         if( Input.GetButton( "Jump" ) ) return 1f;
             else return 0f;
     }
 }
  
 public virtual float horizontal
 {
     get
     {
         float v = Input.GetAxis( "Horizontal" );
         return v * force;
     } 
 } 
 public virtual float vertical
 {
     get
     {
         float v = Input.GetAxis( "Vertical" );
         return v * force;
     } 
 }

 float fr = 0f;
 void Update()
 {
     {
         fr += Time.deltaTime;

         if( Input.GetButton( "Sprint" ) )
         {
             fr += Time.deltaTime*0.5f;
         }

         while( fr >= footsFrequency )
         {
             fr = 0f;

             playFootstepSound();
         }
     }

     
     if( Input.GetButton( "Sprint" ) )
     {
         speed = maxSprintSpeed;
     }
     else speed = maxWalkSpeed;
 }

 public void playFootstepSound()
 {
 }

 void FixedUpdate ()
 {
     ///Jump iteration
     if( !canJump )
     {
         canJumpCounter += Time.fixedDeltaTime;
         if( canJumpCounter >= 1f )
         {
             canJump = true;
             canJumpCounter = 0f;
         }
     }
     
     ////Ground test
     RaycastHit hit;
     
     Vector3 tmpV = transform.position;
     tmpV.y += 0.1f;
     if (Physics.Raycast( tmpV, -Vector3.up, out hit, 0.3f))
     {
         if( hit.collider.tag == "GROUND" )
         {
             grounded = true;
         }
         else
         {
             grounded = false;
         }
     }
     else
     {
         grounded = false;
     }
     
     ////
  
     {
         
     }
     
     {
         Vector3 forceV = Vector3.Cross( hit.normal, Vector3.Cross( transform.forward, hit.normal ) );
         forceV = forceV.normalized;
         
     }
  
     if( jump != 0f && grounded && canJump )
     {
         canJump = false;
         Vector3 tmp = Vector3.up * jumpSpeed + ( transform.forward * vertical * 0.1f );
     }
         
     if( !grounded )
     {

         fallingForce = fallingForce + Time.fixedDeltaTime * 5f;
     }
     else
     {

         fallingForce -= (Time.fixedDeltaTime * 10f) + (fallingForce * 0.3f);
         if( fallingForce < 0f ) fallingForce = 0f;
     }

  }

 void OnCollisionEnter ( Collision other )
 {
     if( other.collider.tag == "GROUND" )
     {
         if( other.relativeVelocity.y >= 2f )
         {
             physicWalk_MouseLook.instance.wobble( 0f, other.relativeVelocity.y * 2f, 0f, other.relativeVelocity.y * 2f );
             
             
             Vector3 tmpPosMod = Camera.main.transform.position;
             tmpPosMod.y -= other.relativeVelocity.y * 0.15f;
             physicWalk_MouseLook.instance._camPos.position = tmpPosMod;
         }
     }
 }

}

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

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

129 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

Related Questions

What is the error? 2 Answers

What does the "compute mesh inertia tensor failed" error mean? 6 Answers

Unity Script causing crash 1 Answer

physics rolling error( included sample and simple demo) 0 Answers

Lynda Tutroial projectile error 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