• 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 Mar 10, 2013 at 03:03 PM by Meater6 for the following reason:

The question is answered, right answer was accepted

avatar image
Question by Meater6 · Mar 26, 2011 at 12:50 PM · javascriptmovementvelocity

Slowing Down When Sliding Across Walls

I have a block that has a rigidbody and a very simple script for moving around:

var speed : float = 10;

function FixedUpdate(){ rigidbody.velocity = Vector3(Input.GetAxis("Horizontal") speed,0,Input.GetAxis("Vertical") speed);
}

I also have some walls that stops the block from going off screen, but when I "Slide" across a wall, with the "wanted" velocity of the block going diagonal, the block moves much slower going across the wall than when just moving through space. This happens even when the wall has no physics material.

How do I make it so that when I slide across the wall, it moves at the same speed as when going through empty space? If there is any scripting involved in your answer, please put it in javascript.

Thanks in advance.

Comment

People who like this

0 Show 0
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

  • Sort: 
avatar image
Best Answer

Answer by Meater6 · Aug 24, 2011 at 05:24 AM

Second Solution!!!

Much better than the last, change the physics material to something frictionless. Works perfectly!

Comment

People who like this

0 Show 0 · 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

Answer by Meater6 · Mar 28, 2011 at 12:41 PM

Problem Solved!

I was able to use Mathf.Clamp to create borders for my block, instead of actual colliders. Here is my completed script:

var speed : float = 10; var height : float = 2;

function Update(){ transform.position.y = height; }

function FixedUpdate(){ rigidbody.velocity = Vector3(Input.GetAxis("Horizontal") speed,0,Input.GetAxis("Vertical") speed);
transform.position.x = Mathf.Clamp(transform.position.x,-20,20); transform.position.z = Mathf.Clamp(transform.position.z,-20,20);

}

Comment

People who like this

0 Show 0 · 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Movement using rigidbody.velocity to apply a constant force until stop 1 Answer

How to get 'real' velocity of an object and not the input velocity? 2 Answers

Adding a slide/velocity effect to a non-rigidbody2D object 0 Answers

How to add max speed to 3D rigidbody? 1 Answer

Grid Based Movement (Pokemon-like) 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