Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 bfbc2jb · Dec 18, 2011 at 05:27 AM · javascriptrigidbodyplayer

custom rigidbody movement problem

hi, im using a custom rigidbody movement script, and it works fine, it moves well and interacts with physics perfectly, but one problem, i can climb up walls witch i dont want, how do i fix that? this is the script, it in javascript:

  var forwardSpeed = 10; 
 
  var backwardSpeed = 5; 
 
  var strafeSpeed = 8; 
 
  
 
  function FixedUpdate () { 
 
     // Step1: Get your input values 
 
     horizontal = Input.GetAxis("Horizontal"); 
 
     vertical = Input.GetAxis("Vertical"); 
 
     // Step 2: Limit the movement on angles and then multiply those results 
 
     // by their appropriate speed variables 
 
     percentofpercent = Mathf.Abs(horizontal) + Mathf.Abs(vertical) - 1.0; 
 
     if (percentofpercent > 0.1) { 
 
        // if we're here, then we're not moving in a straight line 
 
        // my math here might be kinda confusing and sloppy...so don't look! 
 
        percentofpercent = percentofpercent * 10000; 
 
        percentofpercent = Mathf.Sqrt(percentofpercent); 
 
        percentofpercent = percentofpercent / 100; 
 
        finalMultiplier = percentofpercent * .25; 
 
        horizontal = horizontal - (horizontal * finalMultiplier); 
 
        vertical = vertical - (vertical * finalMultiplier); 
 
     } 
 
     if (vertical > 0) { 
 
        vertical = vertical * forwardSpeed; 
 
     } 
 
     if (vertical < 0) { 
 
        vertical = vertical * backwardSpeed; 
 
     } 
 
     horizontal = horizontal * strafeSpeed; 
 
     // Step 3: Derive a vector on which to travel, based on the combined 
 
     // influence of BOTH axes 
 
     tubeFinalVector = transform.TransformDirection (Vector3(horizontal,0,vertical)); 
 
     // Step 4: Apply the final movement in world space 
 
     rigidbody.velocity.z = tubeFinalVector.z; 
 
     rigidbody.velocity.x = tubeFinalVector.x; 
 
  } 
 
  function Awake () { 
 
     rigidbody.freezeRotation = true; 
 
  }

 
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
0

Answer by inkspots · Dec 18, 2011 at 11:42 AM

A good working example of this climbing limitation you describe can be found in the default assets of Unity3d, in the basic character controller there is a so called slopeLimit parameter this is based on steepness angle. So you can have the script decide what angle your rigidbody can ascend prehaps in the case of a wall accept every slope under 90 degrees.

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
0

Answer by storm024 · Dec 18, 2011 at 11:42 AM

declarations:

 var ticktock:boolean;
 var prevPos;
 var pmd;

place in update

 if (!ticktock)
 {
     prevPos = Vector2(transform.position.x,transform.position.z);
     ticktock = true;
 }
 else
 {
     pmd = Vector2.Angle(prevPos,vector2(transform.position.x,transform.position.z));
     ticktock = false;
 }
 if (pmd != null && Raycast (transform.position, Vector3(pmd.x,,pmd., 115, 0))
 {
         rigidbody.velocity.z = 0; 

 rigidbody.velocity.x = 0; 
 }
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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Unity3D Ai wont shoot 1 Answer

Make jump high as long as you press? 0 Answers

How to set max speed for this car ? 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