This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-11-23 21:09:07

ArloarLoLs
Scratcher
Registered: 2012-08-27
Posts: 71

RPG Walking Sideways From Mouse Direction

Hi, I'm working on an RPG game, i have the player point at the mouse forever, and move forward and away from the mouse, but how do I have it move sideways (move left and right but not just the x axis, y axis should also be involved).

Offline

 

#2 2012-11-23 21:57:45

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: RPG Walking Sideways From Mouse Direction

Okay, here's part of it:

if (key [left arrow v] pressed?)
 change x by (([sin v] of (direction)) * [movement])
 change y by (([cos v] of (direction)) * [movement])
end
if (key [right arrow v] pressed?)
 change x by ((0) - (([sin v] of (direction)) * [movement]))
 change y by ((0) - (([cos v] of (direction)) * [movement]))
end

I'm pretty sure I got this much correct, though something might have gone awry.

Anyway, I hope that this helps!

Last edited by ErnieParke (2012-11-23 22:30:58)


http://i46.tinypic.com/35ismmc.png

Offline

 

#3 2012-11-23 22:54:41

ArloarLoLs
Scratcher
Registered: 2012-08-27
Posts: 71

Re: RPG Walking Sideways From Mouse Direction

ErnieParke wrote:

Okay, here's part of it:

if (key [left arrow v] pressed?)
 change x by (([sin v] of (direction)) * [movement])
 change y by (([cos v] of (direction)) * [movement])
end
if (key [right arrow v] pressed?)
 change x by ((0) - (([sin v] of (direction)) * [movement]))
 change y by ((0) - (([cos v] of (direction)) * [movement]))
end

I'm pretty sure I got this much correct, though something might have gone awry.

Anyway, I hope that this helps!

Thanks! I'll try it, but i'm confused by what to put for movement, does 1 = 1 step, or mushc smaller or larger.

Offline

 

#4 2012-11-24 11:58:10

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: RPG Walking Sideways From Mouse Direction

ArloarLoLs wrote:

ErnieParke wrote:

Okay, here's part of it:

if (key [left arrow v] pressed?)
 change x by (([sin v] of (direction)) * [movement])
 change y by (([cos v] of (direction)) * [movement])
end
if (key [right arrow v] pressed?)
 change x by ((0) - (([sin v] of (direction)) * [movement]))
 change y by ((0) - (([cos v] of (direction)) * [movement]))
end

I'm pretty sure I got this much correct, though something might have gone awry.

Anyway, I hope that this helps!

Thanks! I'll try it, but i'm confused by what to put for movement, does 1 = 1 step, or mushc smaller or larger.

Correct, 1 would equal 1 step, and now you just need to replace movement with how many steps you want to move left and right.

Oh, and I'm not sure if I've said this to you yet, but hello and welcome to Scratch!

Last edited by ErnieParke (2012-11-24 11:59:21)


http://i46.tinypic.com/35ismmc.png

Offline

 

#5 2012-11-24 13:17:55

ArloarLoLs
Scratcher
Registered: 2012-08-27
Posts: 71

Re: RPG Walking Sideways From Mouse Direction

ErnieParke wrote:

ArloarLoLs wrote:

ErnieParke wrote:

Okay, here's part of it:

if (key [left arrow v] pressed?)
 change x by (([sin v] of (direction)) * [movement])
 change y by (([cos v] of (direction)) * [movement])
end
if (key [right arrow v] pressed?)
 change x by ((0) - (([sin v] of (direction)) * [movement]))
 change y by ((0) - (([cos v] of (direction)) * [movement]))
end

I'm pretty sure I got this much correct, though something might have gone awry.

Anyway, I hope that this helps!

Thanks! I'll try it, but i'm confused by what to put for movement, does 1 = 1 step, or mushc smaller or larger.

Correct, 1 would equal 1 step, and now you just need to replace movement with how many steps you want to move left and right.

Oh, and I'm not sure if I've said this to you yet, but hello and welcome to Scratch!

XD thanks! Actually ive been using scratch since 2009, i just stopped for a while and made a new account. But again, you've helped alot!  wink

Offline

 

#6 2012-11-24 13:48:46

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: RPG Walking Sideways From Mouse Direction

ArloarLoLs wrote:

ErnieParke wrote:

ArloarLoLs wrote:

Thanks! I'll try it, but i'm confused by what to put for movement, does 1 = 1 step, or mushc smaller or larger.

Correct, 1 would equal 1 step, and now you just need to replace movement with how many steps you want to move left and right.

Oh, and I'm not sure if I've said this to you yet, but hello and welcome to Scratch!

XD thanks! Actually ive been using scratch since 2009, i just stopped for a while and made a new account. But again, you've helped alot!  wink

Well I'm glad to here that!  smile


http://i46.tinypic.com/35ismmc.png

Offline

 

#7 2012-11-24 16:07:49

ArloarLoLs
Scratcher
Registered: 2012-08-27
Posts: 71

Re: RPG Walking Sideways From Mouse Direction

ErnieParke wrote:

ArloarLoLs wrote:

ErnieParke wrote:


Correct, 1 would equal 1 step, and now you just need to replace movement with how many steps you want to move left and right.

Oh, and I'm not sure if I've said this to you yet, but hello and welcome to Scratch!

XD thanks! Actually ive been using scratch since 2009, i just stopped for a while and made a new account. But again, you've helped alot!  wink

Well I'm glad to here that!  smile

By the way, do you happen to know how to move forward and backward?

Offline

 

#8 2012-11-24 16:15:35

ArloarLoLs
Scratcher
Registered: 2012-08-27
Posts: 71

Re: RPG Walking Sideways From Mouse Direction

ErnieParke wrote:

Okay, here's part of it:

if (key [left arrow v] pressed?)
 change x by (([sin v] of (direction)) * [movement])
 change y by (([cos v] of (direction)) * [movement])
end
if (key [right arrow v] pressed?)
 change x by ((0) - (([sin v] of (direction)) * [movement]))
 change y by ((0) - (([cos v] of (direction)) * [movement]))
end

I'm pretty sure I got this much correct, though something might have gone awry.

Anyway, I hope that this helps!

So I tried this code, it is the code for moving forward and backwards XD, do you know how to do left and right?

Offline

 

#9 2012-11-24 16:21:51

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: RPG Walking Sideways From Mouse Direction

ErnieParke wrote:

Okay, here's part of it:

if (key [right arrow v] pressed?)
 change x by (([cos v] of (direction)) * [movement])
 change y by ((0) - (([sin v] of (direction)) * [movement]))
end
if (key [left arrow v] pressed?)
 change x by ((0) - (([cos v] of (direction)) * [movement]))
 change y by (([sin v] of (direction)) * [movement])
end

I'm pretty sure I got this much correct, though something might have gone awry.

Anyway, I hope that this helps!

Ohhh… My mistake.  tongue

Anyway, I fixed the code ^^.

Edit: Fixed again.

Last edited by ErnieParke (2012-11-24 16:24:27)


http://i46.tinypic.com/35ismmc.png

Offline

 

Board footer