The Daily Click ::. Forums ::. Klik Coding Help ::. Overhead view character walkspeed issue
 

Post Reply  Post Oekaki 
 

Posted By Message

Del Duio

Born in a Bowling Alley

Registered
  29/07/2005
Points
  1078

GOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!Evil klikerHasslevania 2!The OutlawSanta Boot
3rd September, 2009 at 19:28:01 -

Okay, here's one I could probably figure out by using the timer object but I feel that's a crappy way of doing it.

What I'm trying to do is have a character's walkspeed in an overhead view game be based off a player stat called (drumroll) WALKSPEED!

The problem is, I have it so that when the player presses up, down, left, or right it adds or subtracts his walkspeed variable to his X or Y position like it should. But if I even increase his walkspeed by a SINGLE DIGIT, to 2, he walks a lot faster. And forget about setting his walkspeed to 3, that's just crazy talk.

Is there some sort of math formula I could use for so that he gradually gets faster as his walkspeed goes up? So that maybe by the time that stat reaches say 10, he's walking as fast as he does now when I set it to 3?

Maybe something like "BLAH" = int("walkspeed"(player) * 0.2) ??

I dunno, what might you suggest if you've done this sort of thing before?

Thanks!!

 
--

"Del Duio has received 0 trophies. Click here to see them all."

"To be a true ninja you must first pick the most stealthy of our assorted combat suits. Might I suggest the bright neon orange?"

DXF Games, coming next: Hasslevania 2- This Space for Rent!

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
3rd September, 2009 at 21:11:52 -

If you set the X and Y positions directly, they get rounded up automatically - which means you can't use a float for a speed value.

The solution is to use alterable values to store the precise X and Y coordinates, and then set the on-screen coordinates from them.

You should always do this with any custom movement.


eg.

* Repeat while "Right" is pressed
-> Player: Add Walk_Speed("Player") to X_Pos("Player")
-> Player: Set X position to X_Pos("Player")

* Repeat while "Left" is pressed
-> Player: Subtract Walk_Speed("Player") from X_Pos("Player")
-> Player: Set X position to X_Pos("Player")

* Repeat while "Down" is pressed
-> Player: Add Walk_Speed("Player") to Y_Pos("Player")
-> Player: Set Y position to Y_Pos("Player")

* Repeat while "Up" is pressed
-> Player: Subtract Walk_Speed("Player") from Y_Pos("Player")
-> Player: Set Y position to Y_Pos("Player")


I hope your method is a bit more sophisticated than that, btw.
For starters, when moving diagonally, you need to divide Walk_Speed by 1.4 (or the squareroot of 2 technically), or it's going to be faster than when moving horizontally or vertically.


Edited by Sketchy

 
n/a

Del Duio

Born in a Bowling Alley

Registered
  29/07/2005
Points
  1078

GOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!Evil klikerHasslevania 2!The OutlawSanta Boot
4th September, 2009 at 00:21:09 -

Oh sorry, they are stored in 2 alt values on the character. What I did is when the player presses the arrows those values increase / decrease and then after all the keypress checks I have an always event that sets the character's X position and Y position to those 2 values. I didn't even think about the 1.4 thing for diagonal though.

Thank you, Sketchy. I'll see what I can come up with.

 
--

"Del Duio has received 0 trophies. Click here to see them all."

"To be a true ninja you must first pick the most stealthy of our assorted combat suits. Might I suggest the bright neon orange?"

DXF Games, coming next: Hasslevania 2- This Space for Rent!

Neuro

Ludologist

Registered
  29/10/2006
Points
  437

Game of the Week WinnerVIP MemberI'm on a BoatPokemon Ball!
4th September, 2009 at 00:30:42 -

I can't believe I haven't been using that, Sketchy... it makes way too much sense! Now I feel enlightened, thank you

 
n/a
   

Post Reply



 



Advertisement

Worth A Click