thanks Game A Gogo, nice clean code. but I made it dirty
I took your code and added sin and cos to keep the view ahead of the actor instead of behind.
note:This code assumes you are already using angle on the actor being followed by the screen. if not you need to add angle coding.
to add:
-put the code into the view's -draw actor -script editor
-add local, real variables called e and c.
-no need to parent anything
-change anyplace that says "player" to your actor's name
-change where it says 160 and 120 to half of your view's x and y dimensions.
- Code: Select all
//this code assumes your player is already assigned an angle
c=sin(degtorad(player.angle))*100;
e=cos(degtorad(player.angle))*100;
// 100 is the distance the view tries to keep
// ahead in either direction
angle=direction(x+160, y+120, player.x+e, player.y-c);
// 160 and 120 are half of my view's pixel dimensions(320x240)
// you must change these to half of your views X and y dimensions
directional_velocity=distance(x+160, y+120, player.x+e, player.y-c)/5;
//change the 160 and 120 here as well
//change the 5 to change how fast the screen follows