Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

C# - Using Transform to move ignores Colliders?

$
0
0
So I'm new to scripting and was using the code below to move my player character which is a cube. using UnityEngine; using System.Collections; public class Player : MonoBehaviour { public float movementSpeed = 25; public float turningSpeed = 60; void Update() { float horizontal = Input.GetAxis("Horizontal") * turningSpeed * Time.deltaTime; transform.Rotate(0, horizontal, 0); float vertical = Input.GetAxis("Vertical") * movementSpeed * Time.deltaTime; transform.Translate(0, 0, vertical); } } However with a Box Collider assigned to both my cube and another cube which is stretched to form a wall, the box passes through it. I can assign a rigidbody to the player cube and it will not pass through the wall cube however physics takes over and the player cube bounces off it or can climb up it when continuing to walk into it. I could tweak the values to prevent drag and such, but I'm sure their is a more simpler way to prevent the player cube from passing through the wall cube. Searched for responses on here but didn't have any luck, any ideas?

Viewing all articles
Browse latest Browse all 171066

Trending Articles



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