Hello there, I wanna create a building system for my game
whenever you click it should create a wall but then again there’s not a collision component in the clone even when I add it to the original it doesn’t do anything, is there a way to fix this?
Here’s my script:
var BuildSystem = pc.createScript('buildSystem');
var items = [36841159];
BuildSystem.attributes.add('wallAsset',{type:'asset',title:'WallAsset'});
// initialize code called once per entity
BuildSystem.prototype.initialize = function() {
this.app.mouse.on(pc.EVENT_MOUSEMOVE, this.onMove, this);
this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.onClick, this);
this.InBuildMode = false;
this.CurrentItem = 36955529;
};
// update code called every frame
BuildSystem.prototype.update = function(dt) {
var camera = this.entity.findByName('Camera');
var pointer = this.app.root.findByName('Pointer');
// inorder to go to build mode
if(this.InBuildMode === false && this.app.keyboard.wasPressed(pc.KEY_Z)){
// enables
this.InBuildMode = true;
this.DisableCamera();
this.app.mouse.disablePointerLock();
}else if (this.app.keyboard.wasPressed(pc.KEY_Z)){
// disables
this.InBuildMode = false;
this.EnableCamera();
this.app.mouse.enablePointerLock();
}
if(this.InBuildMode === true){
// keys
if(this.app.keyboard.wasPressed(pc.KEY_1)){
this.CurrentItem = items[0];
}
// rotation
if(this.app.keyboard.isPressed(pc.KEY_Q)){
pointer.rotate(0,5,0);
}else if (this.app.keyboard.isPressed(pc.KEY_E)){
pointer.rotate(0,-5,0);
}
}
pointer.model.asset = this.CurrentItem;
};
BuildSystem.prototype.onMove = function(event){
};
BuildSystem.prototype.onClick = function(){
var a = this.app.root.findByName('Pointer').clone();
this.app.root.addChild(a);
};
BuildSystem.prototype.DisableCamera = function(){
var camera = this.entity.findByName('Camera');
camera.script.cameraController.enabled = false;
camera.setEulerAngles(-90,0,0);
this.entity.rigidbody.enabled = false;
this.entity.setPosition(this.entity.getPosition().x,40,this.entity.getPosition().z);
};
BuildSystem.prototype.EnableCamera = function(){
var camera = this.entity.findByName('Camera');
camera.script.cameraController.enabled = true;
this.entity.setPosition(this.entity.getPosition().x,1,this.entity.getPosition().z);
this.entity.rigidbody.enabled = true;
};
Thanks for replying…