Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
0
Members

Transform a Vector3

A topic by sheep_knight created May 05, 2016 Views: 527 Replies: 1
Viewing posts 1 to 2

Hello,

So, in my game i would like the player to move considering his orientation, for exemple if the player's character looks on the right, pressing forward will transform the vector 1, 0, 0 to 0, 0, 1. I'm just looking for a transform function, but didn't found something corresponding to what I need. already use this line of code for the movement:

this.actor.cannonBody.body.applyImpulse(new CANNON.Vec3(Sup.Input.getGamepadAxisValue(0,0) * this.speed - v.x, velocity.y - v.y, Sup.Input.getGamepadAxisValue(0,1) * this.speed - v.z), pos);

thanks :)

Nevermind, I've corrected it :

let pos = new CANNON.Vec3(this.actor.getPosition().x, this.actor.getPosition().y, this.actor.getPosition().z);

let vec = new Sup.Math.Vector3(Sup.Input.getGamepadAxisValue(0,0) * this.speed, velocity.y, Sup.Input.getGamepadAxisValue(0,1) * this.speed).rotate(this.actor.getLocalOrientation())

this.actor.cannonBody.body.applyImpulse(new CANNON.Vec3(vec.x - v.x, vec.y - v.y, vec.z - v.z), pos);