Hello Friends I hope all you doing good. so the issue is my character is keep spinning after the jump idk why , i am following this tutorial Video where it shows how to spin character here the code which i have used. Code: //Input Signal variables let _enabled = true; //Node attribute variables let _jumpLimit; let _jumpForce; let _angVel; //working variables let _physics; let _jumpCount = 0; function init(){ //get the node attributes _jumpForce = this.attribute('Jump Force'); _jumpLimit = this.attribute('Jump Limit'); _angVel = this.attribute('Angular Velocity'); //Get and check the Physics status of this entity _physics = this.entity().physics(); if(_physics && _physics.type() != 'kDynamic'){ warning('Jump Node only works with [Dynamic] bodies. Enabling by default'); _physics.setPhysics(true); _physics.setType('kDynamic'); } } function start(){ } function update(dt){ } function signal(name, value){ //Check the incoming signals if(name == 'Jump' && value){ //check we have dynamic physics on the entity if(_physics){ //check here if the signal to jump again is valid //we need to check we are with the jump limit if(_jumpLimit == 0 || _jumpCount < _jumpLimit){ //calculate the jump force to be applied let vel = _physics.linearVelocity(); if(_jumpForce.x != null){ vel.x = _jumpForce.x; } if(_jumpForce.y != null){ vel.y = _jumpForce.y; } if(_jumpForce.z != null){ vel.z = _jumpForce.z; } //apply the jump velocity _physics.setLinearVelocity( vel.x, vel.y, vel.z ); _physics.setAngularVelocity( _angVel.x, _angVel.y, _angVel.z ); //track the jump count _jumpCount++; } } } else if(name == 'Reset' && value){ //Signal to reset the jump so we just reset the //jumpcount variable _jumpCount = 0; } }
Hi there, you forgot to cover the else statement/set the angular velocity to 0 in case that the player exceeds the Jump Limit. Checkout the comment from the code, I think this should work now. PS: You can use our discord server to get live feedback for this type of things instead of creating a thread. (https://discordapp.com/channels/441096670722260992/472195911804780554) Code: //Input Signal variables let _enabled = true; //Node attribute variables let _jumpLimit; let _jumpForce; let _angVel; //working variables let _physics; let _jumpCount = 0; function init(){ //get the node attributes _jumpForce = this.attribute('Jump Force'); _jumpLimit = this.attribute('Jump Limit'); _angVel = this.attribute('Angular Velocity'); //Get and check the Physics status of this entity _physics = this.entity().physics(); if(_physics && _physics.type() != 'kDynamic'){ warning('Jump Node only works with [Dynamic] bodies. Enabling by default'); _physics.setType('kDynamic'); _physics.setPhysics(true); } } function start(){ } function update(dt){ } function signal(name, value){ //Check the incoming signals if(name == 'Jump' && value){ //check we have dynamic physics on the entity if(_physics){ //check here if the signal to jump again is valid //we need to check we are with the jump limit if(_jumpLimit == 0 || _jumpCount < _jumpLimit){ //calculate the jump force to be applied let vel = _physics.linearVelocity(); if(_jumpForce.x != null){ vel.x = _jumpForce.x; } if(_jumpForce.y != null){ vel.y = _jumpForce.y; } if(_jumpForce.z != null){ vel.z = _jumpForce.z; } //apply the jump velocity _physics.setLinearVelocity( vel.x, vel.y, vel.z ); _physics.setAngularVelocity( _angVel.x, _angVel.y, _angVel.z ); //track the jump count _jumpCount++; }else{ // in case that your jumpCount is greater than _jumpLimit or _jumpLimit is not equal to 0 then we need to set the angular velocity to 0 so it will stop spinning _physics.setAngularVelocity( 0, 0, 0 ); } } } else if(name == 'Reset' && value){ //Signal to reset the jump so we just reset the //jumpcount variable _jumpCount = 0; } }
hey bro i copied your code and pasted , its still not working and thx for the discord link i will join <3.
I will have to try this as soon as I am home and see what exactly you want to do with this. Keep an eye on this thread I will add a code based on what I find/manage to do from your request. Here is your code: Code: //Input Signal variables let _enabled = true; //Node attribute variables let _jumpLimit; let _jumpForce; let _angVel; //working variables let _physics; let _jumpCount = 0; function init(){ //get the node attributes _jumpForce = this.attribute('Jump Force'); _jumpLimit = this.attribute('Jump Limit'); _angVel = this.attribute('Angular Velocity'); //Get and check the Physics status of this entity _physics = this.entity().physics(); if(_physics && _physics.type() != 'kDynamic'){ warning('Jump Node only works with [Dynamic] bodies. Enabling by default'); _physics.setType('kDynamic'); _physics.setPhysics(true); } } function start(){ } function update(dt){ } function signal(name, value){ //Check the incoming signals if(name == 'Jump' && value){ //check we have dynamic physics on the entity if(_physics){ //check here if the signal to jump again is valid //we need to check we are with the jump limit if(_jumpLimit == 0 || _jumpCount < _jumpLimit){ //calculate the jump force to be applied let vel = _physics.linearVelocity(); if(_jumpForce.x != null){ vel.x = _jumpForce.x; } if(_jumpForce.y != null){ vel.y = _jumpForce.y; } if(_jumpForce.z != null){ vel.z = _jumpForce.z; } //apply the jump velocity _physics.setLinearVelocity( vel.x, vel.y, vel.z ); _physics.setAngularVelocity( _angVel.x, _angVel.y, _angVel.z ); //track the jump count _jumpCount++; }// This is here to freeze the player rotation mid air if you don't want that effect remove the else statement else{ // in case that your jumpCount is greater than _jumpLimit or _jumpLimit is not equal to 0 then we need to set the angular velocity to 0 so it will stop spinning _physics.setAngularVelocity( 0, 0, 0 ); } } } else if(name == 'Reset' && value){ //Signal to reset the jump so we just reset the //jumpcount variable _jumpCount = 0; if(_physics){ // if you want to freeze the player use: // _physics.setLinearVelocity( 0, 0, 0 ); _physics.setAngularVelocity( 0, 0, 0 ); } } }
and this one is perfect sir thanks for helping me out , i appreciate it only i can see one issue here after jumping its not spinning for sure but character position seems not good see https://prnt.sc/rg5b6d
The mid air spinning issue can be fixed by removing Code: // This is here to freeze the player rotation mid air if you don't want that effect remove the else statement else{ // in case that your jumpCount is greater than _jumpLimit or _jumpLimit is not equal to 0 then we need to set the angular velocity to 0 so it will stop spinning _physics.setAngularVelocity( 0, 0, 0 ); } from the code. as for your screen shot, can you please give me more details?
ya sure bro so as you can see in pic after jumping the character its spins for sure but when character its landing, the position of character is not land perfectly ,https://prnt.sc/rg7xkp check the character when its land on ground the position is weird and its keep going with that position. it needs to be straight in ground , PS: its need to be spin only on air which is working but after landing its need to be straight i hope you understand now , and thank you so much for giving your valuable time to fix this <3
I think this is what are you looking for. Change the else if for "Reset" code to this and see if that is what you want. I added a setRotation line to 0,0,0 on trigger/when the player is grounded. Code: else if(name == 'Reset' && value){ //Signal to reset the jump so we just reset the //jumpcount variable _jumpCount = 0; if(_physics){ // if you want to freeze the player use: // _physics.setLinearVelocity( 0, 0, 0 ); this.entity().setRotation(0, 0, 0); // this force the player's rotation to 0 on collide _physics.setAngularVelocity( 0, 0, 0 ); } }