Question about world space and local space movement
-
- C Programming Expert
- Posts: 10
- Joined: Apr 11, 2021
Question about world space and local space movement
I put together a very simple project to illustrate my question. The goal of this project is to make the shuttle move forward by pressing X on the controller. you can already steer it left and right by using the D-Pad.
You do not have the required permissions to view the files attached to this post.
-
- C Programming Expert
- Posts: 10
- Joined: Apr 11, 2021
To anyone seeing this later, the fine folks from the PSXDEV discord helped me solve the problem! Download the working attachment below to see the code in context.
Here is the function
And here is how to use it in your main loop, or Update function.
Here is the function
Code: Select all
VECTOR pos;
MATRIX omtx;
VECTOR returnPos;
VECTOR Translate (SVECTOR rot, int x, int y, int z) {
pos.vx = x;
pos.vy = y;
pos.vz = z;
RotMatrix(&rot, &omtx);
ApplyMatrixLV(&omtx, &pos, &returnPos);
return returnPos;
}
Code: Select all
//A vector to store your new position
VECTOR newVec;
//This takes the object's rotation and a local direction.
//In this case the Z axis is the object's forward direction.
//So 0, 0, 1 is forward
//0, 1, 0 is up
//and 1, 0, 0 is sideways
//you can replace the 1 with the speed you want your object to move
newVec = Translate(shuttle.rotation, 0, 0, 1 * ONE/500);
yourObject.position.vx += newVec.vx;
yourObject.position.vy += newVec.vy;
yourObject.position.vz += newVec.vz;
You do not have the required permissions to view the files attached to this post.
Who is online
Users browsing this forum: No registered users and 1 guest