Quantcast
Channel: Questions in topic: "interpolate"
Viewing all articles
Browse latest Browse all 93

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

$
0
0
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][1] **Components of other colliders:**![alt text][2] [1]: /storage/temp/119556-unity-2018-06-25-20-40-17.png [2]: /storage/temp/119557-unity-2018-06-25-20-38-26.png **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(); myRigidBody.constraints = RigidbodyConstraints.FreezeRotationX; myCollider = GetComponent(); //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

Viewing all articles
Browse latest Browse all 93

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>