Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //==========
- //Create Event: obj_player
- //==========
- rotateAxis = false;
- rotateSpeed = 2; //<-- Adjusts speed obj_player circles obj_ball
- //==========
- //Step Event: obj_player
- //==========
- if (distance_to_object(obj_ball) <= 64)
- {
- //Distance met, allow rotation.
- rotateAxis = true;
- }
- if (rotateAxis == true)
- {
- //If the player has gone too far away from obj_ball, stop allowing rotation.
- if (distance_to_object(obj_ball) >= 70)
- {
- rotateAxis = false;
- //The distance (Currently 70px) is set greater than 64px, as during rotation
- //the distance between objects may increase slightly (Adjust as desired.)
- }
- //Rotate Around Ball Anti-Clockwise
- if (keyboard_check(ord("S")))
- {
- //Determine angle between ball and player
- pDirection=point_direction(obj_ball.x,obj_ball.y,x,y);
- var xn,yn;
- //Determine new X and Y positions for current step.
- xn = x - sin(pDirection*pi/180)*rotateSpeed;
- yn = y - cos(pDirection*pi/180)*rotateSpeed;
- //Set to new location.
- x = xn;
- y = yn;
- }
- //Rotate Around Ball Clockwise
- if (keyboard_check(ord("W")))
- {
- pDirection=point_direction(obj_ball.x,obj_ball.y,x,y);
- var xn,yn;
- xn = x + sin(pDirection*pi/180)*rotateSpeed;
- yn = y + cos(pDirection*pi/180)*rotateSpeed;
- x = xn;
- y = yn;
- }
- }
Add Comment
Please, Sign In to add comment