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 /
This question was closed Apr 07, 2013 at 08:10 PM by Fattie for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by marowitt · Apr 07, 2013 at 06:27 PM · collisioncontrolrigid body

Objects passing through collision because of transform.translate

Hi,

I have an object that falls using rigidbody.AddForce not the default gravity.

And when you press left/right you move the object in order to navigate around obstacles.

My problem is that the player object will often pass through the wall objects i have even used waitForSecconds to temporary disable the controls but the problem still persists.

 static var power : float = 0.0;
 static var myY : float;
 
 public var upperClampLimit : float; // can be changed form editor
 public var lowerClampLimit : float; // can be changed from editor
 public var fallAcceleration : float; // can be changed from editor
 public var wallSlow : float; //can be changed from editor
 public var movementShrinkerhoriz : float; // can be changed form editor
 public var movementShrinkervert : float; // can be changed form editor
 
 var shouldMove : boolean = true;
  
 function Start(){
  
 rigidbody.freezeRotation = true;
     
 }
     
 function Update (){
 Debug.Log (shouldMove);  
     
 var horiz : float = Input.GetAxis("Horizontal");
 var horizMovement = horiz/movementShrinkerhoriz;
 
 if (shouldMove) {
 transform.Translate(Vector3(horizMovement,0,0));
 }
      
 if (horizMovement!=0){
 rigidbody.velocity.x = 0;
 
 }
      
 var vert : float = Input.GetAxis("Vertical");
 var vertMovement = vert/movementShrinkervert;
 power = power - vertMovement;   
 power = power +fallAcceleration;

 if (power <=0){  
 power = power +fallAcceleration;
 }
 rigidbody.AddForce(Vector3(0,-power,0));
        
 var dist = (transform.position - Camera.main.transform.position).z;
 var upBorder = Camera.main.ViewportToWorldPoint(Vector3(0,upperClampLimit,dist)).y;
 var downBorder = Camera.main.ViewportToWorldPoint(Vector3(0,lowerClampLimit,dist)).y;   
 transform.position.y = Mathf.Clamp(transform.position.y,upBorder,downBorder);
   
 }
     
 function FixedUpdate (){
     
 myY = (rigidbody.position.y);
 rigidbody.transform.position.z = 0;
     
 }
      
 function OnCollisionEnter(theCollision : Collision){  
 if(theCollision.gameObject.name == "wall"){
 shouldMove = false;
 yield WaitForSeconds(0.5);
 shouldMove = true;
 
     
 if (power <=0){
  
 power = power -wallSlow;
 }
       
 }
 }

Comment
Add comment · Show 1
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 Fattie · Apr 07, 2013 at 08:10 PM 0
Share

1 - format your code

2 - search on here for literally 100s of long expanations of this

3 - unityGE$$anonymous$$S.com for beginner articles

4 - Louis has generously given a good answer

1 Reply

  • Sort: 
avatar image
3
Best Answer

Answer by Loius · Apr 07, 2013 at 07:03 PM

Use the 101-010 button to format code.

.Translate and .position are literally teleportation. If you need physics interactions, you have to use CharacterController.Move or .SimpleMove, or use Rigidbody.AddForce

/end copypasta

So to get your thingy to not go through walls, AddForce for the sideways movement as well.

Comment
Add comment · Show 1 · 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 gekabeast · Aug 01, 2021 at 04:30 PM 0
Share

How to make it behave like transform.translate? I need that specific behavior for my game to work. When i addForce the player slides too much, I don't know how to fix that. I know this is an old thread. :)

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

How to make camera position relative to a specific target. 1 Answer

Box collider with rigid body yet enemies still pass through each other. 1 Answer

2D: How to make Gradius III with a mouse? 1 Answer

Object passes through some walls? 1 Answer

Collision detection and prevention between a rigid body and box collider 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