Legacy GM [Solved]Player not orbiting as intended

Hello, I have made a project in which the world can be rotated 90° Left or Right by pressing the Left and Right Arrowkeys.

I want the objects to stay at their positions so they have to rotate/orbit arround the center point. This does work with the big red house and the world itself. I achieved this with.

Create event:

__radius = point_distance(center.x, center.y, x, y)
__dir = point_direction(center.x,center.y,x,y)

Step event:

__theta = global.camrot; // camrot = camera rotation. This is what changes -/+ 90° when arrowkey is pushed

x = center.x + lengthdir_x(__radius,__dir + __theta )
y = center.y + lengthdir_y(__radius,__dir + __theta) //I could just put global.camrot instead of theta but oh well


Houses or Not Moving objects are working fine. But the player for example an object where the dir and radius are chaning/updating as long as the world is not rotating is jumping about in weird 90° increments. You'll see in the video what I mean. The player is not able to move as the world is rotating and I want him to behave like the other things (like The World and the big red house).


Here is the Project
http://www.mediafire.com/file/mp5t837vscq2azs/Testing_3d_Rotating_Camera.zip/file
 

Relic

Member
I won't go through your project file- but if you still need assistance can you show the player step, hopefully showing both where the x and y are updated along with how the movement is 'not allowed' while camera is rotating.
 
Step is:
key_right = (keyboard_check(ord("D")))
key_left = (keyboard_check(ord("A")))
key_down = (keyboard_check(ord("S")))
key_up = (keyboard_check(ord("W")))


vspeed = 0
hspeed = 0

if global.isrot = false {
if(key_right) == true //Movement Code
hspeed = 3
if(key_left) == true
hspeed = -3



if(key_down) == true
vspeed = 3
if(key_up) == true
vspeed = -3
}else{


x = center.x + lengthdir_x(radius,dir+global.camrot)
y = center.y + lengthdir_y(radius,dir+global.camrot)


}

Weird thing is that if I disable the radius and dir variables from refreshing themselves and I start the game the Plr dir shows for example 143.13° but when I then refresh the variables "manually" by pressing a button it show something completely different for example 323.13° although the Player is standing in the exact same place so the angle to the centre point shouldn't have changed at all. When I then Rotate with the 323.13° angle the player makes a jump. But when I dont refresh it and leave it at 143.13° it moves like it should(but ofc I'm not able to move properly because the player is "teleported" to that angle when rotating)

Also many thanks for you trying to help me

Best regards
 

Dev_M

Member
Hey man,

I think your issue might be when the rotation is going from 0 down to 315, and whenit goes from
315 to 0... I had a similar issue when I was making a game with rotation for the cam...
 

Relic

Member
Can you also show where the dir and radius is updated for the player. Not just what the code is, but in relation to where everything else is. If it's not too large, just the entire player step event please. Also - insert the code in a code block in the toolbar above your reply (go to Insert icon or use [*CODE] [/CODE] labels (without the *).
 
Code:
if global.isrot == false{
radius = point_distance(center.x, center.y, x, y)
dir = point_direction(center.x,center.y,x,y)
}
This code is in an alarm in the player that is repeating itself every 8steps(i just wanted a way to automatically Update the variables). I just put a keyboard check arround all that code to update the variables by a press of a button like mentioned before.

The step I sent was basically the entire step event but without some collision code that is not in use and //ed out.

Also im not home right now so this is of the top of my head but it should be right

Best regards
 

Relic

Member
While you haven’t shown this part, I’m guessing global.camrot changes from 0 to 360? Possible even larger and into negatives as well?

I think the issue is your buildings are always being positioned at an angle dir+global.camrot but your player update alarm is ignoring the camera angle and saying the player is at an angle dir while it should be recording the player is at a position dir+global.camrot like everything else.

Try editing your player alarm so:
dir= point_direction()-global.camrot

Excuse the imperfect code, on a phone and cumbersome to type in full.

Edit: changed sign in formula
 
We may be getting closer but we may not.
With
Code:
 point_direction()+global.camrot
the player Jumps only every second rotation
and with
Code:
 point_direction()-global.camrot
it jumps every rotation.

Best Regards
 

Relic

Member
You have reversed your variables in point_direction() in the alarm. You want to know the direction from centre to player, not player to centre.
 
Oh. Would you look at that. I changed that way before thinking it wouldn't make any difference. When I saw it didn't I also forgott to change it back. But in combination with -globalcamrot it seems to work now.

Thank you so much for helping! I really wouldn't have know what to do if you weren't here

Best Regards,
Nick
 
Top