Hi, my name is Laura and I’m an interaction design.
I’m not very good at programming so forgive me the question maybe a little stupid …
I would need to call the entity that selects PickerRaycast to assign a different rotation object.
Maybe I could use getNamedItem () but I do not know how to write code
Someone could kindly help me
thank you so much
my code is this:
var PickerRaycast = pc.createScript('pickerRaycast');
// initialize code called once per entity
PickerRaycast.prototype.initialize = function() {
var app = this.app;
var entity = this.app.root.findByName("antaCubo");
console.log(entity);
this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.onMouseSelect, this);
if (this.app.touch) {
this.app.touch.on(pc.EVENT_TOUCHSTART, this.onTouchSelect, this);
}
};
PickerRaycast.prototype.onMouseSelect = function (e) {
var from = this.entity.camera.screenToWorld(e.x, e.y, this.entity.camera.nearClip);
var to = this.entity.camera.screenToWorld(e.x, e.y, this.entity.camera.farClip);
this.app.systems.rigidbody.raycastFirst(from, to, function (result) {
var pickedEntity = result.entity;
console.log(pickedEntity);
var rotation = pickedEntity.getNamedItem("antaCubo").getRotation();
if ( rotation.y === 0) {
pickedEntity.rotate(0, 180, 0);
pickedEntity.rotate(0, -180, 0);
}
var rotation2 = pickedEntity.getNamedItem("antaMedia").getRotation();
if ( rotation2.x === 0) {
pickedEntity.rotate(0, 180, 0);
pickedEntity.rotate(0, -180, 0);
}
});
};