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:
But 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.whenclicked
foreverchangescroll-x ▼by*sin ▼ofdirectionx-velocitychangescroll-y ▼by*cos ▼ofdirectiony-velocity
Last edited by powerpoint56 (2012-06-11 16:47:20)
Offline
Just make it one variable, velocity. You're probably looking for:
EDIT: 501st post!whenclicked
foreverchangescroll x ▼by*sin ▼ofdirectionvelocitychangescroll y ▼by*cos ▼ofdirectionvelocityifkeyup arrow ▼pressed?changevelocity ▼by1setvelocity ▼tovelocity*0.87
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:
EDIT: 501st post!whenclicked
foreverchangescroll x ▼by*sin ▼ofdirectionvelocitychangescroll y ▼by*cos ▼ofdirectionvelocityifkeyup arrow ▼pressed?changevelocity ▼by1setvelocity ▼tovelocity*0.87
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:
Of course, then you would set the other sprites to "scroll x + 480 * ?" like usual.whenclicked
foreverchangescroll-x ▼byx-velocityifkeyright-arrow ▼pressed?changex-velocityby-1same with below (if left-arrow pressed)ifkeyleft-arrow ▼pressed?changex-velocityby1setx-velocityto((x-velocity)*(0.95))
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:
Of course, then you would set the other sprites to "scroll x + 480 * ?" like usual.whenclicked
foreverchangescroll-x ▼byx-velocityifkeyright-arrow ▼pressed?changex-velocity ▼by-1same with below (if left-arrow pressed)ifkeyleft-arrow ▼pressed?changex-velocity ▼by1setx-velocity ▼tox-velocity*0.95
I think this will work; I'll go check and edit if I need to.
Fixed
Offline