![]() |
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:
|
| All times are GMT +2. The time now is 07:04 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.