Page 1 of 1

Quicker version of makslanes's smooth moving code

PostPosted: Wed Feb 21, 2007 1:29 am
by Game A Gogo
i made a quicker version of makslane's smooth view moving

1.Create an actor that should appear in the middle of the screen.

2.Make view Parent of Center actor.

3.In the center actor draw actor event:
Code: Select all
angle=direction(x, y, Player.x, Player.y);
directional_velocity=distance(x, y, Player.x, Player.y)/10;//Change the number 10 to set the "weight" factor

PostPosted: Thu Feb 22, 2007 2:39 am
by Sgt. Sparky
if the distance is > 25 it messes up!
:(

PostPosted: Fri Feb 23, 2007 12:15 am
by Game A Gogo
distance from what?
This never happened to me, at what actor this happens, and what does exactly happens?

PostPosted: Fri Feb 23, 2007 1:22 am
by Sgt. Sparky
the velocity is so great the view goes away from the players and goes flying all around
:lol:

keeping view ahead of actor

PostPosted: Sat Feb 24, 2007 3:43 am
by pixelpoop
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

PostPosted: Sat Feb 24, 2007 11:34 am
by Troodon
Hmmm...this code is cool but moves the main actor when I change the actor. For example if I make
1.follow actorA
2.follow actorB
the actor B moves little

PostPosted: Wed Aug 01, 2007 3:19 am
by arcreamer
that code u made pixel, when i put it in draw actor of view and made 2 global integer variables e and c, when i put it all in and i clicked game mode, the view went down a little then started shaking like crazy made my head hurt... what happeneD?

PostPosted: Wed Aug 01, 2007 3:21 am
by arcreamer
nvm i got it had to made e and c real variables

PostPosted: Wed Aug 01, 2007 3:40 am
by arcreamer
its not working for me. Whenever i put it in and do everything and go into game mode, whenever i stop the view moves down and to the right and it looks dumb... how do i make it not do that?

PostPosted: Wed Aug 01, 2007 6:48 am
by DilloDude
Maybe put it inside an if (player.directional_velocity) statement. Then it will only move if you are moving. Or use another real variable instead of angle.

PostPosted: Wed Aug 01, 2007 10:38 am
by pixelpoop
do you have a directional velocity on your actor that the view follows? You need to have one even if it is .0000000001
Here is a demo:

PostPosted: Wed Aug 01, 2007 2:57 pm
by arcreamer
thanks pixel i got it working