- Home /
Why doesnt my checkpoint system work?
Hi, im currently trying to get a checkpoint system to work in my game, I have a Kill Volume(as shown in picture 1) that when you touch it, it spawns you back at the beginning, as shown in picture 2!
Which spawns you back here!!!
And when you hit a checkpoint, shown as the other square in picture two, the kill volume should spawn you at the checkpoint(square2) rather than the original spawn point(square 1).
This is my killVolume code, which sends you to the original starting zone
var dest: Transform; // drag the destination object here
function OnTriggerEnter(other: Collider){
if (other.tag == "Player"){
// move the player and align it to the dest object:
other.transform.position = dest.position;
other.transform.rotation = dest.rotation;
I have this so far as code to spawn me at square two
static var dest: Transform;
function OnTriggerEnter(item : Collider) {
if(item.tag == "Player")
{
"RestartScript".dest.Transform = "Checkpoint1".Transform; } }
It obviously not working, which is where you all come in. Any ideas on what I could change for the checkpoint script? I have it to where it will respawn the player at the original spot(square1) when I die, but when I hit the checkpoint and die, it doesnt spawn me at the checkpoint(square2).
You already posted that question and had answers for that issue 2 days ago. Did you try them?
Answer by Flash · Apr 20, 2012 at 12:35 AM
On your "Kill Volume" add a variable called something like "RespawnPosition" of type Transform like so.
var RespawnPosition:Transform;
Also add a tag to your kill volume called "deathzone" or something similar.
In your checkpoint script write this for the OnTriggerEnter function.
function OnTriggerEnter(other:Collider){
var killzone : GameObject;
killzone = GameObject.FindGameObjectWithTag("deathzone");
killzone.GetComponent(killVolume).RespawnPosition = transform;
}
Now when respawning the player (on your kill volume) do.
function OnTriggerEnter(other: Collider){
if (other.tag == "Player"){
// move the player and align it to the dest object:
other.transform.position = RespawnPosition.position;
other.transform.rotation = RespawnPosition.rotation;
}
}
This will make sure that your kill volume knows at which point to respawn the player and it will also make sure that the kill volume actually spawns the player at that point.
0
kk i entered everything in, currently getting this error in the checkpoint script:
Assets/Scripts/Checkpoint.js(4,34): BCE0005: $$anonymous$$ identifier: 'killVolume'.
I double checked and made sure my killVolume had the right tag on it, which is deathzone
here is the script:
function OnTriggerEnter(other:Collider){
var killzone : GameObject;
killzone = GameObject.FindGameObjectWithTag("deathzone");
killzone.GetComponent(typeof(killVolume)).RespawnPosition =transform;
}
kk tried putting quotes around killVolume, got these errors:
GetComponent requires that the requested component 'String' is inherited or implemented by 'killVolume'. UnityEngine.GameObject:GetComponent(Type) Checkpoint:OnTriggerEnter(Collider) (at Assets/Scripts/Checkpoint.js:4)
NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cache$$anonymous$$eyName, System.Type[] cache$$anonymous$$eyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cache$$anonymous$$eyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value) Checkpoint.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/Checkpoint.js:4)
Well the "killVolume" should be the script that is controlling your kill zone.. If that makes sense. Try removing the "typeof()" and just go with:
killzone.GetComponent(killVolume).RespawnPosition =transform;
I normally don't use Javascript (I use C#) so I may have screwed up the "GetComponent" function in my original answer.
You should. Let me explain what the script does line by line.
1: function OnTriggerEnter(other:Collider){ 2: var killzone : GameObject; 3: killzone = GameObject.FindGameObjectWithTag("deathzone"); 4: killzone.GetComponent(killVolume).RespawnPosition = transform; 5: }
LINE 1: This declares the function "OnTriggerEnter" and takes a parameter of type "Collider".
LINE 2: Here we declare a variable of type "GameObject" local to the "OnTriggerEnter" function.
LINE 3: Here we select the object in our scene that has the tag "deathzone" and stores it in the variable we created on line 2. This is why I wanted you to assign that tag to your kill volume.
LINE 4: Now we access the "killVolume" script (That you made and dragged onto the kill volume in the editor) and assign the "transform" of our checkpoint (Where this script is placed) to the "RespawnPosition" variable on the "kill volume" object.
LINE 5: You know this one but here we close the "OnTriggerEnter" function.
Can you try the script above and tell me if it gives you an error again? If it does then I'm pretty sure I know what's wrong. Also remember to actually create the "RespawnPosition" variable on your kill volume.
wow lol works perfectly now, lol derp move on my part, thxs alot man u rock!
Your answer
Follow this Question
Related Questions
Checkpoint script problem 1 Answer
Help with SendMessage 1 Answer
How do I randomize the order of spawn points without repeats? 1 Answer
Respawning my AVATAR 1 Answer
Checkpoint system??? 3 Answers