Hi!
This is my first time really playing around with LOVE and I must say that I'm really enjoying it! Especially after working with the Flex SDK and getting many headaches.
My problem isn't specific to LOVE, but hopefully it's legit to ask help about it here. I am trying to make a system where you control a character from top-down view and it's supposed to ease into a grid (for neatness), but I simply cannot figure out how to get it to work without making the character jitter. See, I want it to ease at the sides at the same speed that it moves forward, but as a result it eases too fast so when it tries to ease into the grid it actually passes the grid so it goes back and forth skipping the point that it's supposed to ease into. I tried many things to fix this. I tried making it slower so it goes pixel by pixel, but that's too slow for what I want. I tried doing many mathematical hacks, but even my best one occasionally eased it at least a pixel off par, which ruins it.
To anyone who wants a better idea of what I'm trying to do, this guy wrote a neat article about it: http://troygilbert.com/2006/10/19/the-m ... -of-zelda/
I attached the love file I'm working with. The faulty/incomplete code is right under "-- FIX: Jitters". I'm sorry if my code isn't as pretty as it could be. I tried my best to at least comment it helpfully.
Any help at all would be super-appreciated!
Easing character to grid (help)
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Easing character to grid (help)
- Attachments
-
- viator0.love
- (1.36 KiB) Downloaded 120 times
Re: Easing character to grid (help)
The problem is that sometimes (mob[0]x/y * dt) puts you across a grid line so the next iteration has to move in the other direction, but again, the increment is to much, thus the jitter.
Try this in update:
Try this in update:
Code: Select all
local xr = mob[0].x % 16
local yr = mob[0].y % 16
local xoffset = 0
local yoffset = 0
if(xr < (mob[0].speed * dt)) then xoffset = xr else xoffset = (mob[0].speed * dt) end
if(yr < (mob[0].speed * dt)) then yoffset = yr else yoffset = (mob[0].speed * dt) end
if(hormove == 1 and vertmove == 0 and mob[0].y % 16 > 8 and mob[0].y % 16 ~= 0) then mob[0].y = mob[0].y + yoffset
elseif(hormove == 1 and vertmove == 0 and mob[0].y % 16 <= 8 and mob[0].y % 16 ~= 0) then mob[0].y = mob[0].y - yoffset
elseif(hormove == 0 and vertmove == 1 and mob[0].x % 16 > 8 and mob[0].x % 16 ~= 0) then mob[0].x = mob[0].x + xoffset
elseif(hormove == 0 and vertmove == 1 and mob[0].x % 16 <= 8 and mob[0].x % 16 ~= 0) then mob[0].x = mob[0].x - xoffset
end
Re: Easing character to grid (help)
Oh wow, you are too awesome. That works perfect! :
THANK YOU SO MUCH!
THANK YOU SO MUCH!
Who is online
Users browsing this forum: No registered users and 88 guests