Moving one point to another at a static speed
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Moving one point to another at a static speed
I tried messing around with vectors for a bit to attempt to move the player towards the selected grid at a static speed, but no dice. I have attached two versions of the code - one in which the played is moved towards the intended position by continuously subtracting the difference between it's current position and intended position from it's current position (the problem with this is that player speed decreases the closer it gets to the target), and another in which I attempted to use tween to interpolate the path on which to move, which just results in a delay before the player is instantaneously teleported, along with bugging out a bit.
- Attachments
-
- withtween.love
- (1.75 MiB) Downloaded 307 times
-
- notween.love
- (1.75 MiB) Downloaded 311 times
Last edited by SudoCode on Sat Sep 29, 2012 6:46 pm, edited 1 time in total.
Re: Moving one point to another at a static speed
Your love files are incorrectly packaged. Here you go: Game Distribution
(common error is archiving the source directory, you should be archiving the source directory contents)
(common error is archiving the source directory, you should be archiving the source directory contents)
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
Re: Moving one point to another at a static speed
What? Everything works fine for me.
Re: Moving one point to another at a static speed
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
-
- Prole
- Posts: 6
- Joined: Mon Aug 27, 2012 10:21 am
Re: Moving one point to another at a static speed
I had a similar problem when using gridlocked movement (only moving single hexes in my case but similar enough).
Try calculating the move_distance_x and move_distance_y between the start point and end point of the move, then use something like:
..where player.speed is the number of seconds to move one grid square.
Try calculating the move_distance_x and move_distance_y between the start point and end point of the move, then use something like:
Code: Select all
if player.moving == true then
player.act_x = player.act_x - (player.move_distance_x / grid_square_width / player.speed * dt)
player.act_y = player.act_y - (player.move_distance_y / grid_square_width / player.speed * dt)
-- force final actual x & y to exact grid x & y of movement aim point
if math.abs(player.act_x - player.grid_x) < 1 then player.act_x = player.grid_x end
if math.abs(player.act_y - player.grid_y) < 1 then player.act_y = player.grid_y end
if player.act_x == player.grid_x and player.act_y == player.grid_y then
player.moving = false
end
end
Re: Moving one point to another at a static speed
Hi, try this:
BTW, I don't know what this whole Beholder is (I'm new), but you should fix the way the clicked tile is being detected. I think there is a small delay between the click and the measurement, and it makes you overshoot the desired tile if you aim far.
Code: Select all
function moveControlled(dt)
local maxspeed = 200
-- where do we want to go
local dx = controlled.grid_x - controlled.act_x
local dy = controlled.grid_y - controlled.act_y
-- how far is it
local len = math.sqrt(dx^2 + dy^2)
-- if it's too far then limit the speed
if len > maxspeed * dt then
controlled.act_x = controlled.act_x + dx * dt * maxspeed / len
controlled.act_y = controlled.act_y + dy * dt * maxspeed / len
else
controlled.act_x = controlled.grid_x
controlled.act_y = controlled.grid_y
end
end
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Moving one point to another at a static speed
I have the same error as Lafolie. Are you sure you are trying the .love files, and not on your uncompressed folder instead?SudoCode wrote:What? Everything works fine for me.
When I write def I mean function.
Re: Moving one point to another at a static speed
Yep, main.lua is in the root directory and world.lua is in src/game. I tried downloading the files from those links and they worked fine as well, unless Chrome is launching different versions of the files or something.kikito wrote:I have the same error as Lafolie. Are you sure you are trying the .love files, and not on your uncompressed folder instead?SudoCode wrote:What? Everything works fine for me.
In any case, I managed to get movement at a static speed working thanks to Przemator, but I can't seem to reproduce overshooting the tiles. I would prefer to use tween if it can be used for this sort of thing, because I'll probably want to use it for something else in the future.
edit: it appears that overshooting the tiles is linked to maxSpeed. Doesn't seem to overshoot with a value of 100.
Last edited by SudoCode on Sat Sep 29, 2012 6:56 pm, edited 1 time in total.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Moving one point to another at a static speed
I get the same error. I see you have a directory src/game/world as well as a module src/game/world.lua. That could be the source of the problem: Lua tries to load "src/game/world" before it tries "src/game/world.lua" and it sees that it exists, but when it tries to open "src/game/world" it gets an error because it's a directory, not a file.
Renaming one or the other should fix things.
Renaming one or the other should fix things.
Help us help you: attach a .love.
Re: Moving one point to another at a static speed
Sorry, I wasn't aware of that
I just deleted the folder since I'm not using it yet anyway.
I just deleted the folder since I'm not using it yet anyway.
- Attachments
-
- AStar.love
- (1.75 MiB) Downloaded 338 times
Who is online
Users browsing this forum: No registered users and 4 guests