PDA

View Full Version : Scripting movement.


Angel_Light
04-29-2006, 11:11 PM
Hello,

Is there any way to just advance the player foreward without reading player x y. Like just if the player is facing north east and the player just presses the up arrow and he moves foreward, north east. Then he rotates and turns south west and pushes the up and the player moves south west.

Is there anyway to do this?

Skyld
04-29-2006, 11:20 PM
Hello,

Is there any way to just advance the player foreward without reading player x y. Like just if the player is facing north east and the player just presses the up arrow and he moves foreward, north east. Then he rotates and turns south west and pushes the up and the player moves south west.

Is there anyway to do this?
disabledefmovement; will disable the default movement, and then you can script your own movement system from there using keypressed/keydown, and by altering the player's X and Y manually. You will have to do manual onwall detection, swimming, sleeping, and sword use also, though.

ApothiX
04-29-2006, 11:52 PM
Hello,

Is there any way to just advance the player foreward without reading player x y. Like just if the player is facing north east and the player just presses the up arrow and he moves foreward, north east. Then he rotates and turns south west and pushes the up and the player moves south west.

Is there anyway to do this?
For what you're talking about, you'd have to do something like:
player.x += cos(this.angle);
player.y += -sin(this.angle);

this.angle being the angle the player is facing.

Angel_Light
04-30-2006, 03:55 AM
ok thank you two ^^

EDIT: Ok i got the image to move but it only moves horzontaly. No matter what direction the player faces. :/
I believe the player.y is being read.

Tyhm
05-01-2006, 10:30 AM
Maybe it's not -sin(this.angle).
Maybe it's just sin(this.angle). Or tan(this.angle). Play around with it, it's been years since I did the X and Y of a sin of an angle (and even then I stood on the shoulders of Sardon)

Angel_Light
05-01-2006, 02:20 PM
One problem tho. I'm still Algebra 1. -_- I havent learn sin cos or tan...

Yen
05-01-2006, 09:13 PM
One problem tho. I'm still Algebra 1. -_- I havent learn sin cos or tan...

Aw, that's so cute.
I see no reason for tan in a movement system.

x,y -> cos(angle), single(angle)
cos is for the x-axis, sin is for the y-axis.
Graal uses angles in radians (0 to pi*2), instead of degrees (0 to 360)
However, if you don't understand radians, you can use the 'degtorad(angle)' function to convert degrees to radian.

player.x += cos(angle) will move the player's x at that angle.
player.y -= sin(angle) will move the player's y at that angle.

The the angle 0 is facing right, then cos(0), -sin(0) will be -1, 0
The angle pi*.25 (.785), or 45 degrees if you prefer that, is between the directions right and up. So, if you use cos(.785), -sin(.785), the player will move to the upper-right.

You could use getangle(gotox - player.x, gotoy - player.y) to find the angle from one point to another.

Oyah, this stuff is trigonometry, not algebra.

ApothiX
05-01-2006, 10:18 PM
Just to clarify, player.y -= sin(angle) is the same as player.y += -sin(angle), Tyhm, you shouldn't post if you don't know what you're talking about. It's not helping anything.

Angel_Light
05-02-2006, 01:58 AM
Sweet. A Math Teacher on Graal =B Thanks, i think i'm getting it.....

Shaun
05-02-2006, 03:58 AM
Wait wait, who's the math teacher in this post?

Blitz_Hunter
05-02-2006, 04:19 AM
probably yen

Angel_Light
05-02-2006, 04:52 AM
Yup ^^

ZeLpH_MyStiK
05-02-2006, 06:28 AM
tan...if you ever needed to divide the change in y movement by the change in x movement...

Andy0687
05-02-2006, 07:00 AM
Just to clarify, player.y -= sin(angle) is the same as player.y += -sin(angle), Tyhm, you shouldn't post if you don't know what you're talking about. It's not helping anything.

I honestly think all he was trying to do was encourage him to play around a little with the script (Judging by him saying he didnt know much about the topic himself) thats all.

pacMASTA
05-02-2006, 07:27 AM
Aw, that's so cute.
I see no reason for tan in a movement system.

x,y -> cos(angle), single(angle)
cos is for the x-axis, sin is for the y-axis.
Graal uses angles in radians (0 to pi*2), instead of degrees (0 to 360)
However, if you don't understand radians, you can use the 'degtorad(angle)' function to convert degrees to radian.

player.x += cos(angle) will move the player's x at that angle.
player.y -= sin(angle) will move the player's y at that angle.

The the angle 0 is facing right, then cos(0), -sin(0) will be -1, 0
The angle pi*.25 (.785), or 45 degrees if you prefer that, is between the directions right and up. So, if you use cos(.785), -sin(.785), the player will move to the upper-right.

You could use getangle(gotox - player.x, gotoy - player.y) to find the angle from one point to another.

Oyah, this stuff is trigonometry, not algebra.

Yen you surpise me. Anyway Graal math is screwed up I've never asked graal but i think its a Hybrid version of Trignonometry; Theirs tons of things for starters wtf is up with the X and Y plane?

Angel_Light
05-02-2006, 02:21 PM
So, your saying trigonometry is screwed, pacMASTA?

ApothiX
05-02-2006, 03:17 PM
Yen you surpise me. Anyway Graal math is screwed up I've never asked graal but i think its a Hybrid version of Trignonometry; Theirs tons of things for starters wtf is up with the X and Y plane?
top left->bottom right is common in a lot of games. Graal math isn't screwed up, the people who don't know how to use it, are ;)

Tyhm
05-03-2006, 03:13 AM
You just have to remember that in computer graphics everything is Quandrant 4 whereas in school everything is Quadrant 1.
2|1
-0-
3|4

Which is silly, as it's the only time I've seen things go counterclockwise from 90 degrees by way of definition.

And yeah, I was suggesting tinkering until it worked. That's the only way I've ever scripted anything - make a grandiose plan, find out it doesn't work, try adding and subtracting brackets and +1s until it kinda works, figure out why that helped, rescript it, repeat.

Angel_Light
05-03-2006, 05:51 AM
dont forget the stuff with the z axis =P

pacMASTA
05-03-2006, 06:53 AM
You just have to remember that in computer graphics everything is Quandrant 4 whereas in school everything is Quadrant 1.
2|1
-0-
3|4

Which is silly, as it's the only time I've seen things go counterclockwise from 90 degrees by way of definition.

And yeah, I was suggesting tinkering until it worked. That's the only way I've ever scripted anything - make a grandiose plan, find out it doesn't work, try adding and subtracting brackets and +1s until it kinda works, figure out why that helped, rescript it, repeat.

Quadrent for was always Taught to be +,-; Which is what really blows my mind and Graal is not a good calculator its crazy as hell some times and very easy and great to use others; Btw Triginomatry sucks its the only class i got a C/B :( and got beat for it

Angel_Light
05-04-2006, 07:24 AM
So trigonometry is smarter than you pacMASTA? =P

Angel_Light
07-24-2006, 07:32 AM
Hello all again, I basically abandoned this script long ago becuase of more important stuff and now that I'm done with that stuff I want to finish this script,

if (params[0]=="37") {
with (findimg(455)) {
rotation += pi/100;
}
}
else if (params[0]=="38") {
with (findimg(455)) {
player.x += cos(this.angle);
player.y += sin(this.angle);
}
}
else if (params[0]=="39") {
with (findimg(455)) {
rotation -= pi/100;
}
}
else if (params[0]=="40") {
with (findimg(455)) {
player.x -= cos(this.angle);
player.y -= sin(this.angle);
}
}


thats part of the script. I want it to move the player & img on the direction the imgs rotatation. Any thought of how to make this happen. Right now it only moves left to right and if I put quotes around this.angleit move diagonally, either goes north east or south west.

to Yen : ( I've tried contacting you through AIM but you arnt on when I am)

Angel_Light
07-26-2006, 07:35 AM
Any thought???

Polo
07-26-2006, 12:29 PM
1) Your using the images rotation variable to store the angle, but 'this.angle' in your trig parts (which isn't changing as a result). On a side note, personally I would store your own variable for rotation, then rotate the image to match this.

2) Why are you using the with() when your only changing the player parts (blocks 2 and 4)?

3) I wouldn't use the cursor ASCII code 37-40, as some people use different cortrols. Try to use keydown() instead.

Angel_Light
08-01-2006, 12:15 AM
function onTimeout() {
drawunderplayer();
this.boatX = x + 1.5;
this.boatY = y + 2;
this.boatW = getimgwidth("niromia_playerboat.gif")/16;
this.boatH = getimgheight("niromia_playerboat.gif")/16;
roatation = this.angle;
with (findimg(455)) {
stretchx = 0.5;
stretchy = 0.5;
x = thiso.boatX - thiso.boatW[0]/2;
y = thiso.boatY - thiso.boatH[0]/2;
image = "niromia_playerboat.gif";
layer = 0;
}
setTimer(0.05);
}


I made it so rotation equals this.angle. but it moves now just in the right direction, I messed and toyed with it and no luck _-_ I dont understand radicals and radtodeg doesnt help me

Skyld
08-01-2006, 12:24 AM
http://library.thinkquest.org/20991/media/alg2_radians.gif

degtorad(#) returns degrees converted to radians.
radtodeg(#) returns radians converted to degrees.

Angel_Light
08-01-2006, 03:37 AM
o.o thanks

EDIT: HOORAY!!! I got it to work becuase of that chart ^o^ Thank-you so much skyld. ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ :cool: