How to make an object spin

I’m trying to make my object spin and I’m to stupid to find out what the code is to do it, and I’m not doing it with input, I just want it to spin on its own forever, example: Karlson

2 Likes

Hi! @Nicholas_Taylor1 do you want to press a key to make it spin?

no, i just want it to spin on its own

image no, i just want it to spin on its own.

Well in that case paste this into your function code

this.entity.rotateLocal(0,1,0)

You can increase the value to make it faster or decrease to make it slower if you want

won’t it only make it spin on the Y axis though?

or will changing the 0’s spin it along those axis’ too?

1 Like

image won’t it only make it spin on the Y axis though?

Yes you can put the zero on the X or Z axis as well?

Does the code work for you?

let me see

image

let me see you script paste it into a text

its literally just a standard script(if you had just created a new one) with that code in it

1 Like

Hold on a second

var Spin = pc.createScript('spin');

// initialize code called once per entity
Spin.prototype.initialize = function() {
    
};

// update code called every frame
Spin.prototype.update = function(dt) {
    
};

this.entity.rotateLocal(0,1,0);

// initialize code called once per entity
Spin.prototype.initialize = function() {
    
};

// update code called every frame
Spin.prototype.update = function(dt) {
       this.entity.rotateLocal(0,1,0);  
};
1 Like

alrighht i’ll try that

1 Like

Does it work?

yes

Good job! glad to see you as a new developer on PlayCanvas. If you need help feel free to contact the forums or me directly.

ok, thank you for your help

Cheers
----Nicholas

1 Like

oh, one more thing

if i did want it to be rotated on input(not like forever, but rotated a little bit and then stopped, then rotated back to the original rotation on key release), would it be

if (app.keyboard.isPressed(pc.KEY_E)) {
         this.entity.rotateLocal(0,1,0);
        
    }
1 Like