Hi I’m almost done with a project for one of my classes and it’s supposed to be a TPC
Essentially every object in my game has a collision and a rigid body, and supposedly to every object there’s a text box that should appear above it. How it works is when my character collides with the object the textbox should appear.
I used the same code for another project and it worked perfectly, but for the other one Im working on now, isn’t working at all. Can I get some help?
here’s my code for my Character Movement
var GuyMovement = pc.createScript('guyMovement');
// initialize code called once per entity
GuyMovement.prototype.initialize = function() {
this.entity.collision.on('collisionstart', this.OnCollsionStart, this)
this.entity.collision.on('collisionend', this.OnCollsionEnd, this)
};
// update code called every frame
GuyMovement.prototype.update = function(dt) {
if (this.app.keyboard.isPressed(pc.KEY_W)){
this.entity.rigidbody.applyForce(0,0,-5);
}
if (this.app.keyboard.isPressed(pc.KEY_S)){
this.entity.rigidbody.applyForce(0,0,5);
}
if (this.app.keyboard.isPressed(pc.KEY_D)){
this.entity.rigidbody.applyForce(5,0,0);
}
if (this.app.keyboard.isPressed(pc.KEY_A)){
this.entity.rigidbody.applyForce(-5,0,0);
}
if (this.app.keyboard.isPressed(pc.KEY_SPACE)){
this.entity.rigidbody.applyForce(0,5,0);
}
};
GuyMovement.prototype.OnCollisionStart = function(result) {
if (result.other.name == "Disco") {
this.app.root.findByName("infobox1").enabled = true;
}
if (result.other.name == "Patrick") {
this.app.root.findByName("infobox2").enabled = true;
}
if (result.other.name == "Wrestler") {
this.app.root.findByName("infobox3").enabled = true;
}
if (result.other.name == "Mouse") {
this.app.root.findByName("infobox4").enabled = true;
}
if (result.other.name == "Jellyfish") {
this.app.root.findByName("infobox5").enabled = true;
}
if (result.other.name == "Kid") {
this.app.root.findByName("infobox6").enabled = true;
}
if (result.other.name == "Peasant") {
this.app.root.findByName("infobox7").enabled = true;
}
if (result.other.name == "Speakers") {
this.app.root.findByName("infobox8").enabled = true;
}
if (result.other.name == "Walt") {
this.app.root.findByName("infobox9").enabled = true;
}
if (result.other.name == "Stage") {
this.app.root.findByName("infobox10").enabled = true;
}
};
GuyMovement.prototype.OnCollisionEnd = function(result) {
if (result.name == "Disco") {
this.app.root.findByName("infobox1").enabled = false;
}
if (result.name == "Patrick") {
this.app.root.findByName("infobox2").enabled = false;
}
if (result.name == "Wrestler") {
this.app.root.findByName("infobox3").enabled = false;
}
if (result.name == "Mouse") {
this.app.root.findByName("infobox4").enabled = false;
}
if (result.name == "Jellyfish") {
this.app.root.findByName("infobox5").enabled = false;
}
if (result.name == "Kid") {
this.app.root.findByName("infobox6").enabled = false;
}
if (result.name == "Peasant") {
this.app.root.findByName("infobox7").enabled = false;
}
if (result.name == "Speakers") {
this.app.root.findByName("infobox8").enabled = false;
}
if (result.name == "Walt") {
this.app.root.findByName("infobox9").enabled = false;
}
if (result.name == "Stage") {
this.app.root.findByName("infobox10").enabled = false;
}
};
// swap method called for script hot-reloading
// inherit your script state here
// GuyMovement.prototype.swap = function(old) { };
// to learn more about script anatomy, please read:
// https://developer.playcanvas.com/en/user-manual/scripting/
Everything should be in order, I also double checked the scene to make sure everything is titled correctly.
here’s the link to the project I’m currently working on
https://playcanvas.com/editor/scene/1939391
and here’s the original project Im basing my code off on
https://playcanvas.com/editor/scene/1956850
I would really appreciate some quick help!