J
JoeCruz
Guest
So atm i can rotate the camera and the player matches the camera angle, im trying to add/subtract the angle of the camera view to the movement code of the player.
if i rotate the camera 180* and move the player up, it will actually be moving down, because its not taking into account the camera rotation. How could i go about implementing this rotation into the movement?
here's my player's step event:
variable for camera rotation is global.z and i just add or subtract to that by pressing Q/E to rotate it
any help or tips would be appreciated :3
if i rotate the camera 180* and move the player up, it will actually be moving down, because its not taking into account the camera rotation. How could i go about implementing this rotation into the movement?
here's my player's step event:
GML:
// Inputs
right = keyboard_check(ord("D"));
left = keyboard_check(ord("A"));
up = keyboard_check(ord("W"));
down = keyboard_check(ord("S"));
close_game = keyboard_check(ord("R"));
var dirX, dirY, dir;
// Reset the direction
dirX = 0;
dirY = 0;
if (right || left)
{
dirX = right - left;
}
if (up || down)
{
dirY = down - up;
}
// Calculate the direction that the player needs to move
dir = point_direction(0, 0, dirX, dirY);
// Move the player
var currentSpeed = point_distance(0, 0, velocity[@ X], velocity[@ Y]);
// Horizontal movement
if (right || left)
{
if (abs(currentSpeed) >= spd)
{
velocity[@ X] = lengthdir_x(spd, dir);
}
else
{
velocity[@ X] += lengthdir_x(acc, dir);
}
}
else
{
velocity[@ X] = lerp(velocity[@ X], 0, fric)
}
// Vertical movement
if (up || down)
{
if (abs(currentSpeed) >= spd)
{
velocity[@ Y] = lengthdir_y(spd, dir);
}
else
{
velocity[@ Y] += lengthdir_y(acc, dir);
}
}
else
{
velocity[@ Y] = lerp(velocity[@ Y], 0, fric)
}
Code:
//global cam angle
camera_set_view_angle(view_camera[0],global.z)
any help or tips would be appreciated :3