![]() |
Scripting movement.
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? |
Quote:
|
Quote:
player.x += cos(this.angle); player.y += -sin(this.angle); this.angle being the angle the player is facing. |
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. |
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) |
One problem tho. I'm still Algebra 1. -_- I havent learn sin cos or tan...
|
Quote:
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. |
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.
|
Sweet. A Math Teacher on Graal =B Thanks, i think i'm getting it.....
|
Wait wait, who's the math teacher in this post?
|
probably yen
|
Yup ^^
|
tan...if you ever needed to divide the change in y movement by the change in x movement...
|
Quote:
|
Quote:
|
So, your saying trigonometry is screwed, pacMASTA?
|
Quote:
|
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. |
dont forget the stuff with the z axis =P
|
Quote:
|
So trigonometry is smarter than you pacMASTA? =P
|
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,
PHP Code:
to Yen : ( I've tried contacting you through AIM but you arnt on when I am) |
Any thought???
|
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. |
PHP Code:
|
http://library.thinkquest.org/20991/...g2_radians.gif
degtorad(#) returns degrees converted to radians. radtodeg(#) returns radians converted to degrees. |
o.o thanks
EDIT: HOORAY!!! I got it to work becuase of that chart ^o^ Thank-you so much skyld. ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ :cool: |
| All times are GMT +2. The time now is 04:55 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.