Hi, I am making a game but my player (capsule) keeps walking through all the houses. I have been trying to add wall colliders but they are not working. (its 3rd person)
Here is my movement code.
using UnityEngine;
public class playerController : MonoBehaviour {
public float mSpeed;
// Use this for initialization;
void Start () {
mSpeed = 10f;
}
// Update is called once per frame
void Update () {
transform.Translate(mSpeed * Input.GetAxis("Horizontal") * Time.deltaTime, 0f, mSpeed * Input.GetAxis("Vertical") * Time.deltaTime);
}
}
here is the 3rd person camera code;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ThirdPerspnScript: MonoBehaviour
{
public GameObject target;
public float rotateSpeed = 5;
void Start()
{
transform.parent = target.transform;
transform.LookAt(target.transform);
}
void LateUpdate()
{
float horizontal = Input.GetAxis("Mouse X") * rotateSpeed;
float vertical = Input.GetAxis("Mouse Y") * rotateSpeed;
target.transform.RotateAround(target.transform.position, Vector3.up, horizontal);
target.transform.RotateAround(target.transform.position, Vector3.left, vertical);
}
}
** finally my mouse aim code; **
using UnityEngine;
public class MouseAimCamera : MonoBehaviour
{
public GameObject target;
public float rotateSpeed = 100f;
Vector3 offset;
void Start()
{
offset = target.transform.position - transform.position;
}
void LateUpdate()
{
float horizontal = Input.GetAxis("Mouse X") * rotateSpeed;
target.transform.Rotate(0, horizontal, 0);
float desiredAngle = target.transform.eulerAngles.y;
Quaternion rotation = Quaternion.Euler(0, desiredAngle, 0);
transform.position = target.transform.position - (rotation * offset);
transform.LookAt(target.transform);
}
}