So, I'm doing this car racing game where your car can go in any direction and it changes scroll-x/scroll-y appropriately. I found a script I could use to make it scroll in any direction:
when gf clicked forever change [scroll-x v] by (([sin v] of (direction)) * (x-velocity)) change [scroll-y v] by (([cos v] of (direction)) * (y-velocity)) endBut now I'm totally dumbfounded. What do I set the velocities to? What do I do to make the screen move when the arrow keys? I know how to do regular scrolling with x and y, but not anything of the sort above.
Last edited by powerpoint56 (2012-06-11 16:47:20)
Offline
Just make it one variable, velocity. You're probably looking for:
when gf clicked forever change [scroll x v] by (([sin v] of (direction)) * (velocity)) change [scroll y v] by (([cos v] of (direction)) * (velocity)) if <key [up arrow v] pressed?> change [velocity v] by (1) end set [velocity v] to ((velocity) * (0.87))EDIT: 501st post!
Last edited by chanmanpartyman (2012-06-10 19:50:28)
Offline
Do you understand trig? If you don't ill be glad to summarize what this script does and why it works.
Offline
chanmanpartyman wrote:
Just make it one variable, velocity. You're probably looking for:
when gf clicked forever change [scroll x v] by (([sin v] of (direction)) * (velocity)) change [scroll y v] by (([cos v] of (direction)) * (velocity)) if <key [up arrow v] pressed?> change [velocity v] by (1) end set [velocity v] to ((velocity) * (0.87))EDIT: 501st post!
Thanks!!!
Offline
Wes64 wrote:
Do you understand trig? If you don't ill be glad to summarize what this script does and why it works.
Thanks! Can you?
Offline
powerpoint56 wrote:
Wes64 wrote:
Do you understand trig? If you don't ill be glad to summarize what this script does and why it works.
Thanks! Can you?
So in very rough, basic terms...
Imagine a circle with a radius. No matter what direction the radius is pointed in, it always is the same length, right? Basically, sin(Direction) and cos(Direction) describe a radius of that circle. They give you the slope of that radius.
So in the script, your "radius" length is equal to the velocity variable, and the sin and cos give you the slope of that radius. Because you have the slope, you can scroll in any direction, and the velocity thing makes it smooth.
Offline
is it possable to make x volocity in a scrolling game?
Offline
captaincrunch wrote:
is it possable to make x volocity in a scrolling game?
Yes. Here's what I'd do:
when gf clicked forever change [scroll-x v] by (x-velocity) if <key [right-arrow v] pressed?> change (x-velocity) by (-1) //same with below (if left-arrow pressed) end if <key [left-arrow v] pressed?> change (x-velocity) by (1) end set (x-velocity) to (((x-velocity)*(0.95))) endOf course, then you would set the other sprites to "scroll x + 480 * ?" like usual.
Offline
powerpoint56 wrote:
captaincrunch wrote:
is it possable to make x volocity in a scrolling game?
I think this will work; I'll go check and edit if I need to.
Works!
Offline
powerpoint56 wrote:
captaincrunch wrote:
is it possable to make x volocity in a scrolling game?
Yes. Here's what I'd do:
when gf clicked forever change [scroll-x v] by (x-velocity) if <key [right-arrow v] pressed?> change [x-velocity v] by [-1] //same with below (if left-arrow pressed) end if <key [left-arrow v] pressed?> change [x-velocity v] by (1) end set [x-velocity v] to <(x-velocity) * [0.95]>Of course, then you would set the other sprites to "scroll x + 480 * ?" like usual.
I think this will work; I'll go check and edit if I need to.
Fixed
Offline