- Home /
My character is ignoring some collisions
My chararcet as colliders. the other objcts have colliders, but my character keeps getting inside of stuff, like walls, the problem i think is in the transform.translate. could anyoune help me?? My jumping its also bugging any gess?? my character code is here:
using UnityEngine; using System.Collections;
public class walkperson : MonoBehaviour { public float velocidade; public float voo; public GameObject bala; public float timeLeft;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Class1.contadorglobal == 0)
{
if (Input.GetKey("w"))
{
transform.Translate(0, 0, velocidade);
timeLeft -= Time.deltaTime;
if (timeLeft < 0)
{
GetComponent<AudioSource>().volume = Random.Range(0.8f, 1);
GetComponent<AudioSource>().pitch = Random.Range(0.8f, 1.1f);
GetComponent<AudioSource>().Play();
timeLeft = 0.5f;
}
}
}
if (Input.GetKey("a"))
{
transform.Translate(-velocidade, 0, 0);
}
if (Input.GetKey("s"))
{
transform.Translate(0, 0, -velocidade);
}
if (Input.GetKey("d"))
{
transform.Translate(velocidade, 0, 0);
}
if (Input.GetKey("space"))
{
transform.Translate(0, velocidade, 0);
}
the problem isn´t the collider because when i use the unity car he dont go trought walls the probleme is because of the tranforme.translate, pls can anyone change my code to something who dont bug. thanks.
...I don't know try with FixedUpdate ins$$anonymous$$d of Update, I had a similiar problem, that for a some milleseconds the character was trapassing the walls, I used FixedUpdate, and I have decereased the FixedDeltatime calls in a second to 0.01 (project settings --> time -->Fixed timestep, but this will make your game heavyer)
Answer by luis-boavida · Feb 23, 2017 at 09:42 AM
I had done some search and i will change the translate, to move or to rigidbody.addforce. thanks for the answers