is it possible to rotate an object? PlayCanvas | HTML5 Game Engine. i tried to add touch input but it’s doesn’t woriking
Hi @Dann,
Take a look at this example, it uses mouse input. You can add touch input events similarly:
https://developer.playcanvas.com/en/tutorials/rotating-objects-with-mouse
I tried but still can’t.
This example includes touch events, I’ve just tried it on my phone and it works as expected:
if (this.app.touch) {
this.app.touch.on(pc.EVENT_TOUCHSTART, this.onTouchStart, this);
this.app.touch.on(pc.EVENT_TOUCHMOVE, this.onTouchMove, this);
}
TouchInput.prototype.initialize = function() {
if (this.app.touch) {
this.app.touch.on(pc.EVENT_TOUCHSTART, this.onTouchStart, this);
this.app.touch.on(pc.EVENT_TOUCHMOVE, this.onTouchMove, this);
}
};
I’ve try this still can’t rotate. i try put the script on character and pattern maker still can’t
Yes, it’s not enough to copy/paste, most likely some changes will be required to adjust it to your project.
If you are able try sharing a project link to take a look.
here’s my project https://playcanvas.com/editor/scene/1042344
Here you go, I’ve updated your project to being able to rotate the character on the marker:
https://playcanvas.com/editor/scene/1046358
Things I did:
- Added a pivot entity parent entity to the character, so I can rotate the character without messing with the AR placement.
- Fixed your rotate script to include an
entity.rotateLocal()
statement. Touch input was working correctly, you just didn’t go all the way to actually rotating the character.
thanks now it works