Page 1 of 1

like aoe

PostPosted: Fri Mar 23, 2007 9:57 pm
by kes
hi, its me again, now im trying to do the view move like in the Real Time Strategy games, but just in the x axis

PostPosted: Fri Mar 23, 2007 10:22 pm
by Sgt. Sparky
draw actor for view:
Code: Select all
angle = direction(x + width / 2, y + height / 2, Player.x, y + height / 2);
directional_velocity = distance(x + width / 2, y + height / 2, Player.x, y + height / 2) / 25;

that should work :D
notice that I do not use Player.y,
that is because you do not want the view to move up and down :D

PostPosted: Sat Mar 24, 2007 2:55 am
by kes
thanks man!! you saved my game again!!

PostPosted: Sat Mar 24, 2007 1:04 pm
by DilloDude
rather than using y + height / 2, you could set then both to 0, since they are both the same. That way, it will not have to calculate y + height /2 every time. Also, if you are just using the x axis, the whole thing could be simplified to
Code: Select all
xvelocity = (Player.x - (x + width * .5)) / 25;
I changed width / 2 to width * .5, since it should be more efficient. if you know the width of your screen, you can just put that to be faster still. If you are using 800x600, you would put in 400 instead of width * .5. 1024x 768 would be 512. If you wanted to use it in multiple places you could make it a define. Put
Code: Select all
#define halfwidth 512
in Global Code (or whatever the value is). Then, instead of the width * .5, you can just put halfwidth. This is easier to remember, plus if you are using it in multiple places, and you want to change the resolution, you only have to change one place.

PostPosted: Sat Mar 24, 2007 6:48 pm
by Sgt. Sparky
I just used the + height /2 + width /2 ect. stuff to make it so you would not have to just start out with the calculations,
you could also do in global
Code: Select all
#define halfX view.width / 2
#define halfY view.height / 2

:D
so you could replace the x + view.width or height / 2
with x + halfX
or y + half Y

PostPosted: Sun Mar 25, 2007 1:09 am
by UltimatHedgehog
Sgt. Sparky wrote:draw actor for view:
Code: Select all
angle = direction(x + width / 2, y + height / 2, Player.x, y + height / 2);
directional_velocity = distance(x + width / 2, y + height / 2, Player.x, y + height / 2) / 25;

that should work :D
notice that I do not use Player.y,
that is because you do not want the view to move up and down :D

how do i make the veiw switch to do this after i collide with something

PostPosted: Sun Mar 25, 2007 6:06 pm
by Sgt. Sparky
make a global var called Able.
then on the draw actor for the view actor
use this
Code: Select all
if(Able == 1)
{
   angle = direction(x + width / 2, y + height / 2, Player.x, y + height / 2);
   directional_velocity = distance(x + width / 2, y + height / 2, Player.x, y + height / 2) / 25;
}

on collision on whatever side you want of the collideactor,
Code: Select all
Able = 1;

:D
EDIT:
you can also use if Able is 2 to make the view move to a different actor :D

PostPosted: Sun Mar 25, 2007 11:57 pm
by UltimatHedgehog
i want it to follow it in y too so i added Player infront of y too but it made veiw go down so my feet were sticking down from off screen when i jumped to the higher platform
see i already have veiw going like that. I want it to change there so i can get to the higher spot and have veiw go up so im centered then go back to just x when i touch the second part of the higher platform

see what happened
Image

PostPosted: Mon Mar 26, 2007 12:52 am
by Sgt. Sparky
then use player.y instead of y + height / 2 :D