- Home /
Object goes trough everything (Teleporting?)
I have a little big problem. I'm making a game and i need an object to follow the player when not seen, everything is working fine except for 1 thing... The object moves trough the floor, walls and everything on it's way without giving a single fuck about it (like a baws). Idk if it's because of the LookAt or the Translate variables, but i think the second one causes it. It's like it teleports instead of moving behind the player.
Here is the script:
#pragma strict
var player : Transform;
var statue : Transform;
var speed : float = 0.5;
var RockDragging: AudioClip;
function Update(){
if(renderer.isVisible == false){
statue.LookAt(player);
statue.Rotate(player);
statue.Translate(speed*Vector3.forward);
audio.clip = RockDragging;
audio.Play();
}
}
function OnBecameVisible() {
audio.clip = RockDragging;
audio.Pause();
}
Answer by RomanorumLegio · Aug 16, 2013 at 04:09 AM
The first thing I notice is that you are using transform.Translate which ignores physics. If you want it to collide with other objects, both involved objects should have colliders, and you should use ridgedbody.AddForce to move said objects.
More than likely you will have to set up a form of path-finding too, and I have no experience with that.
Edit
I know that I can blabber at times, so let me make a checklist to clear things up:
Check that the moving object is a rigidbody. (tutorial)
Check that both the moving object and the player have colliders. (tutorial)
Set the statue variable to a RigidBody instead of a Transform
Set the object to move with AddForce instead of translate (tutorial)
Final script should look something like this:
#pragma strict
var player : Transform;
var statue : Rigidbody; //redefined Transform to Rigidbody
var speed : float = 0.5;
var RockDragging: AudioClip;
function Update(){
if(renderer.isVisible == false){
statue.LookAt(player);
statue.Rotate(player);
statue.rigidbody.AddForce(speed*Vector3.forward); //changed movement by translate to addforce
audio.clip = RockDragging;
audio.Play();
}
}
function OnBecameVisible() {
audio.clip = RockDragging;
audio.Pause();
}
//I reformated to what I'm used to. There is no need to change your formating.
//If there is a syntax error, I appologize. I almost exclusively use C#.
By the way, are you making something similar to SCP : Containment Breach?
Sorry for the late answer. I'm planning on making something similar to SCP-173, if you want to compare it with something related with the SCP Foundation universe
Also, i didn't really understood what to do. Can i haz example script?
No worries about the speed; we all have obligations in real life to fulfill.
I updated my answer to something that should help you more.
Your answer
![](https://koobas.hobune.stream/wayback/20220613112318im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Object rotating around object at two levels 1 Answer
Attach a Player to a moving GameObject 0 Answers
Teleporting Script Doesn't Work With Anything But The Player 1 Answer
Mouse as a throttle 1 Answer
Helicoper Movement Help 1 Answer