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 /
avatar image
0
Question by omarsolarte · Apr 23, 2015 at 05:30 PM · collisionmovementcolliderwall collision

player collite with object and start moonwalking

trouble with collision with an object when the player collite with and object the player start to walk like moonwalk from the opposite direction if i do a debug.log to position the x positio or the y position start to increas o decrease an this look like moving by himself.

player like rigidbody and a box collider , the object a cube has rigidbody and a box collider this is the code i have the game is a 2d with movement from left to right also up and down

  void FixedUpdate (){
     float h = Input.GetAxis ("Horizontal");         //for A D input
     float v = Input.GetAxis ("Vertical");         //for W S input
 
     hMove = h * xSpeed;   
     //When input Horizontal is true, multiply h by moveSpeed
     vMove = v * ySpeed;    
     //as above, but referenced to Vertical
     zMove = v * zSpeed;                    
     //as above, but for Depth
         
     //... Free the speed from framerate's tiranny...
     hMove *= Time.deltaTime; 
     vMove *= Time.deltaTime;    
     zMove *= Time.deltaTime;                   
     
         
     //This line tells the game what to do with the lines above, that is to Move.
     if (collite == false) {
         Debug.Log (collite);
         transform.Translate (hMove, 0.0f, zMove, Space.World);       
     } 
     
     //... And animate, referencing to absolute values since negatives would be wrong!    
     if ((Mathf.Abs (Input.GetAxisRaw ("Horizontal")) != 0) || (Mathf.Abs (Input.GetAxis ("Vertical")) != 0)) {    
         anim.SetFloat ("Speed", Mathf.Abs (1));
     
     } 
     else {    
         anim.SetFloat ("Speed", Mathf.Abs (0));
     
     }
 
     if((facingRight && h < 0) ||  (!facingRight && h > 0)){                    
         //this is the other way around
         Flip ();
     }
 }
 void OnCollisionEnter(Collision other){    
     if (other.gameObject.name == "Wall")   {    
         Debug.Log(other.gameObject.name);    
         rigidbody.velocity = new Vector3(0, rigidbody.velocity.y, 0);    
         //rigidbody.AddForce ((Vector3.left * 10.0f));    
     }
 }
 
  

thanks for the help

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 omarsolarte · Apr 24, 2015 at 03:56 PM 0
Share

ok finally found the answer looking youtube video and some code only for those that need help in this the trouble was i was using translate and when use translate the rigidbody is hard to control so i cahnge the movement with velocity and force and rigth now everything is O$$anonymous$$ so that was the answer jajajaja

1 Reply

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

Answer by omarsolarte · Apr 24, 2015 at 06:11 PM

ok finally found the answer looking youtube video and some code only for those that need help in this the trouble was i was using translate and when use translate the rigidbody is hard to control so i cahnge the movement with velocity and force and rigth now everything is OK so that was the answer jajajaja

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

2 People are following this question.

avatar image avatar image

Related Questions

Player shaking when colliding with objects 3 Answers

Movement Collisions for Flat NPC with Character Controller 0 Answers

How to tag? 1 Answer

plain problem with collider. begginer in unity 3 Answers

Cannot move FPSController after respawning at a spawn point. 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