• 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
1
Question by StevenFiji · Jun 26, 2018 at 01:14 AM · collisioncolliderinterpolationinterpolaterigibody

Player starts moving in one direction nonstop after colliding with any other object

My current issue is that when my player capsule collides with any other object that has a collider it starts to move nonstop in the opposite direction of the collision.

Player Components: alt text

Components of other colliders:alt text

Player Controller Code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 [RequireComponent(typeof(Rigidbody))]
 public class PlayerController : MonoBehaviour {
 
     //Public Variables
 
     public Rigidbody myRigidBody;
     public Collider myCollider;
     public float playerSpeed = 25;
     public float playerRotationSpeed;
 
     //public LayerMask whatIsGround;
     //public bool isGrounded;
 
     //Private Variables
 
     private float hAxis;
     private float vAxis;
 
     private Camera mainCamera;
 
     private void Start()
     {
 
         myRigidBody = GetComponent<Rigidbody>();
         myRigidBody.constraints = RigidbodyConstraints.FreezeRotationX;
         myCollider = GetComponent<Collider>();
         //whatIsGround = 1 << 9;
         mainCamera = Camera.main;
 
     }
 
     private void Update()
     {
 
         hAxis = Input.GetAxisRaw("Horizontal");
         vAxis = Input.GetAxisRaw("Vertical");
 
         //GroundCheck();
         LookAtMouse();
 
     }
 
     private void FixedUpdate()
     {
 
         Vector3 moveInput = new Vector3(hAxis, 0, vAxis).normalized;
         myRigidBody.MovePosition(transform.position + moveInput * playerSpeed * Time.deltaTime);
 
     }
 
     //private void GroundCheck()
     //{
 
     //    Ray groundCheck = new Ray(transform.position, Vector3.down);
     //    if (Physics.Raycast(groundCheck, 1.71f, whatIsGround, QueryTriggerInteraction.Ignore))
     //    {
 
     //        isGrounded = true;
 
     //    }
     //    else
     //    {
 
     //        isGrounded = false;
 
     //    }
 
     //}
 
     private void LookAtMouse()
     {
 
         Ray cameraRay = mainCamera.ScreenPointToRay(Input.mousePosition);
         Plane groundPlane = new Plane(Vector3.up, Vector3.zero);
         float rayDistance;
 
         if (groundPlane.Raycast(cameraRay, out rayDistance))
         {
 
             Vector3 pointToLookAt = cameraRay.GetPoint(rayDistance);
             transform.LookAt(new Vector3(pointToLookAt.x, transform.position.y, pointToLookAt.z));
             //Debug.DrawLine(cameraRay.origin, pointToLookAt, Color.red);
 
         }
 
     }
 
 }
 


Link to video with example: https://vimeo.com/276993825?utm_source=email&utm_medium=vimeo-cliptranscode-201504&utm_campaign=28749

Video Password: Unity

unity-2018-06-25-20-40-17.png (65.6 kB)
unity-2018-06-25-20-38-26.png (68.9 kB)
Comment
Add comment · Show 4
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 someguywithamouse · Jun 26, 2018 at 02:05 AM 0
Share
avatar image NoDumbQuestion · Jun 26, 2018 at 02:26 AM 1
Share
avatar image StevenFiji NoDumbQuestion · Jun 26, 2018 at 02:33 AM 0
Share
avatar image NoDumbQuestion StevenFiji · Jun 26, 2018 at 02:35 AM 0
Share

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AshwinLahare · May 11, 2019 at 10:06 AM

I have the same problem. Looks like it's a bug.

A workaround that has worked well for me is to increase the Radius of the Sphere Collider of the Player just up to the point till it encompasses most of the gun (you can leave the tip of the muzzle out and instantiate bullets from there). The obstacle then collides with the bigger Sphere Collider and the Player stays in place however you collide it.alt text

T$$anonymous$$s will however, make your player easier to $$anonymous$$t if shot at.


workaround.jpg (364.3 kB)
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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

149 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 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

Problems with collision under certain circumstances. 0 Answers

OnCollisionStay2D is ignoring OnCollisionEnter2D 2 Answers

Collision not working 1 Answer

Interpolation issue, some items not being interpolated correctly. 0 Answers

Unwanted jittery behavior 2 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