Hello, I’m trying to make a horror game and my code isn’t working at all, it says I have to define it and I don’t know what that means. can someone please help me!
I need alot more information than “define it”. Ironically enough you didnt define what the problem is either and I dont know what it is,
Ok, I’ve trying to make a horror game with code from a already solved problem but it didn’t work. when I try to play it says it needs to be defined. Im not sure what “define” means though but I’ll give the link to it.
you need to make it
this.entity.rigidbody.teleport(new pc.Vec3(-0.026,-19.459,-1.498));
instead of
this.entity.rigidbody.Teleport(new pc.Vec3(-0.026,-19.459,-1.498));
it still says I have to define Teleport
On line 14 and 18 of your script Teleport
should be Jumpscare
, because your script has the name Jumpscare
instead of Teleport
.
Please also note you currently have two initialize functions in your script. Only the first one will be executed.
ok, i tried that but it didnt work. now it says " Uncaught TypeError: this.entity.rigidbody.Jumpscare is not a function"
Then you changed the wrong line.
here’s the code, I only changed 14 and 18.
var Jumpscare = pc.createScript('jumpscare');
// initialize code called once per entity
Jumpscare.prototype.initialize = function() {
};
// update code called every frame
Jumpscare.prototype.update = function(dt) {
};
// initialize code called once per entityqqqqqqqq
Jumpscare.prototype.initialize = function () {
this.entity.collision.on('collisionstart', this.onCollisionStart, this);
};
Jumpscare.prototype.onCollisionStart = function (result) {
if (result.other.name === "Monster") {
this.entity.rigidbody.Jumpscare(new pc.Vec3(-0.026,-19.459,-1.498));
}
};
On line 20 Jumpscare
should be teleport
, like @lifeofpain already mentioned.
Please beware you still have an initialize function on line 4 till 6 and a second one on line 14 till 16, while there only should be one initialize function in a script.
Hello, can you pls send me the edited code, I don’t know what I’m doing. I think I messed it up more.
var Jumpscare = pc.createScript('jumpscare');
// initialize code called once per entity
Jumpscare.prototype.initialize = function () {
this.entity.collision.on('collisionstart', this.onCollisionStart, this);
};
// update code called every frame
Jumpscare.prototype.update = function(dt) {
};
Jumpscare.prototype.onCollisionStart = function (result) {
if (result.other.name === "Monster") {
this.entity.rigidbody.teleport(new pc.Vec3(-0.026,-19.459,-1.498));
}
};
Thanks for the code but its still messed up. it has a bunch of problems.
The reason is probably because the entity with the script has no collision component at the moment.
You know, its really hard to help someone when all the feedback they give is “it has a bunch of problems”. Perhaps send screenshots of the object, and the premise of what exactly the code is supposed to do.
it already has collisions.
its supposed to teleport you to a room with a bunch of scary pictures when you touch the “monster”. right now when I try it all that happens is the monster teleports.
Alright, this is going to sound like a weird plug for my project but I promise it isnt. So I am currently working on an example project fps, and in the fps there are some grenades. The grenades have dynamic rigidbodies and yet they are moved around and stuff. Tell me if you think that would be helpful to you.
(you might have to play for a bit because the room with the grenades is only unlocked after you shoot all the plates)
ALUCARDS FIRST PERSON SHOOTING | Launch
Also if the music changes in the background just ignore that I am actively working on it right now.
Was this helpful at all?
ok so you want to modify the code to be
var Jumpscare = pc.createScript('jumpscare');
Jumpscare.attributes.add('player',{type:'entity'});
// initialize code called once per entity
Jumpscare.prototype.initialize = function () {
this.entity.collision.on('collisionstart', this.onCollisionStart, this);
};
// update code called every frame
Jumpscare.prototype.update = function(dt) {
};
Jumpscare.prototype.onCollisionStart = function (result) {
if (result.other.name === this.player.name) {
this.player.rigidbody.teleport(new pc.Vec3(-0.026,-19.459,-1.498));
}
};
This code will cause the player entity to teleport to the coordinates in the onCollisionStart function. You must define the player entity in the editor by parsing the script with the parse button then selecting the player entity in the script.