![]() |
simple movement help.
Hi forums. I am trying to make a simple movement system where i can move left and right. and that's it.
Ill show what i have but can some one please modify because it seems buggy and the movement is not as instant as the default one. Also, if someone could add the tile detection so he can't walk though walls that'd be great. Please explain also, as I am trying to take not and learn. //#CLIENTSIDE function onCreated() { canmove = 1; disabledefmovement; } function onKeyPressed(temp.code, temp.key, temp.scan) { if (canmove = 1) { if (keydown(3)) { player.x +=0.3; player.dir = 3; setAni("walk", NULL); setTimer(0.3); } else if (keydown(1)){ player.x -=0.3; player.dir = 1; setAni("walk", NULL); setTimer(0.3); } } } function onTimeOut() { setAni("idle", NULL); } |
PHP Code:
PHP Code:
|
Quote:
I've restyled your code to the same standard nearly everyone else follows on these forums and placed comments above the lines that may have been causing problems. PHP Code:
PHP Code:
|
OK. So here is an update of the script. the colliding of walls does still not work. Im using onwall2 because i am using the "era" tile template. (not actually using those tiles, just the tile setup where they are) and also, there is a delay on the movement. you have to hold the key for a second for the movement to actually work.
//#CLIENTSIDE function onCreated() { movePlayer(); this.canmove = 1; disabledefmovement(); } function onKeyPressed(temp.code, temp.key, temp.scan) { if (this.canmove == 1) { if (keydown(3)) { player.x +=0.3; player.dir = 3; setAni("walk", NULL); setTimer(0.5); } else if (keydown(1)){ player.x -=0.3; player.dir = 1; setAni("walk", NULL); setTimer(0.5); } } } function onTimeOut() { setAni("idle", NULL); } function movePlayer(){ temp.new_x = player.x +0.3; temp.new_y = player.y; if (!onwall2(temp.new_x, temp.new_y)) { player.x = temp.new_x; player.y = temp.new_y; } } |
My example wasn't something you could just paste in, you have to use it in your movement code. Also please put your code in PHP tags so it's easier to read.
|
I didn't just paste it in :/
I'll figure it out i guess. But how do you do PHP tags, Im new to forums. |
1. For me it seems like you will do a detection for each arrow key you press. Probably it´s good for the beginning learning it but I´d take a look at this.
It´s an easy and short movement script where I´m sure you can learn good from. 2. PHP Code:
Quote:
|
Quote:
|
| All times are GMT +2. The time now is 03:23 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.