- Home /
Problem is not reproducible or outdated
Why does my player fly through my barrier?
I want to create an invisible barrier that my player will just bump into if it collides into it. I followed this thread to create my barrier https://answers.unity.com/questions/52283/invisible-walls.html. It works pretty well for the most part except for the fact that if I keep bumping into the wall, the player can go right through it. How would I fix this?
The page you linked doesn't work. $$anonymous$$ake sure you aren't editing the transform of the player directly and ins$$anonymous$$d move it by changing the rigidbodys velocity or using the Rigidbody.$$anonymous$$ovePosition function.
Answer by Ginxx009 · Jan 17, 2018 at 02:36 AM
First thing to check if do all your invisible barrier have Colliders on them? Are the Collider's "Is Triggers" box clicked on?
Second thing If you have a Rigidbody and all the proper Colliders and you're not ignoring the collisions via code or anything like that.. Try setting your Rigidbody's Collision Detection to "Continuous".
Discrete Detection: Checks the next frame "Is the collider touching another collider in this frame? If not, move there, if so, we collided"
Continuous Detection: Fires a Raycast in the direction of movement to check the collision before they happen.
And Third is please post your code in the reply section so i can help you with the code . Cause maybe it is your problem
I checked the "Is Trigger" box for the Collider and this caused the player to die when it touched the collider. I set the Collision Detection to Continuous but it doesn't seem like it did anything. This is the code I have for the barrier:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class BarrierController : $$anonymous$$onoBehaviour {
// Use this for initialization
void Start () {
GetComponent<Rigidbody> ().velocity = new Vector3 (0, 0, 7);
}
}
This is the code for the Collision: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class DestroyContact : $$anonymous$$onoBehaviour {
PlayerController player$$anonymous$$ovement;
CameraController camera$$anonymous$$ovement;
public GameObject player;
// public Camera camera; public ParticleSystem particleSystemPlayer; public Vector3 PosofDeadPlayer;
void Awake()
{
player$$anonymous$$ovement = GetComponent <PlayerController> ();
// camera$$anonymous$$ovement = GetComponent(); }
void OnTriggerEnter (Collider other)
{
if (other.gameObject.tag == "Floor") {
return;
}
if (other.gameObject.tag != "Floor") {
Destroy (gameObject);
PlayerisDead ();
}
}
void PlayerisDead()
{
player$$anonymous$$ovement.enabled = false;
// camera$$anonymous$$ovement.enabled = false;
PosofDeadPlayer = player.transform.position;
particleSystemPlayer.transform.position = PosofDeadPlayer;
particleSystemPlayer.Play (true);
}
}
Follow this Question
Related Questions
Ragdoll with multiple colliders 0 Answers
Adding components to 3d models 1 Answer
stop objects moving through each other 5 Answers