Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Move to target

I am making my custom battle system but I can't figure out how to move a battler to its target. that's all i need at the moment. if someone knows please post.

Edit: It is a turn-based system, not an active system or else. I just want the battler image, or picture move toward the enemy.
 

Star

Sponsor

There's not enough information. First of all we have no idea what battle system you are trying to make.

If it's an Action Battle System try using a Pathfinding Script. I used that for mine and it works wonders. If you want it I can post it
 
I don't think what you need is a pathfinding script... these are meant to figure out fast ways through mazes, around corners or choose the faster of two or more routes - in other words, none of which you need to move a battler to another. Instead, all you want to do is move your sprites, using @sprite.x and @sprite.y; now for movement, move it a certain amount of pixels each frame (in other words, each time update is called). That could for example look like this:

[rgss]class Scene_Battle
  def update
    if @sprite.x > 200 # assuming 200 is the default x value for the battler
      @sprite.x += @attacking ? 1 : -1 # moves the sprite to the right if attacking and to the left if retreating
    elsif @sprite.x >= 400 and @attacking # assuming 400 is the maximum x value, as in the position you'll actually execute your attack animation...
      # ...which is why your attack animation code goes here, and if done, set @attacking to false
    elsif @sprite.x < 200
      @sprite.x = 200 # set the sprite's x value to 200 in case you messed up somewhere
    end
  end
end
[/rgss]

Now this is just a very rough example of how you could do it... of course you need to wrap it up and make it shiney on your own. If you need further help, or if I was completely off with my explanation and you knew all that, feel free to tell me/us :p


Off-topic, I like how your system is both turn-based AND active time... you should mix some RTS and beat'em up in there if possible :p </sarcasm>
 
hm that might help, but the i just can't figure how to make the battle wait until it is finished.

well i want to have an ATB add-on, but it's rather complicated. i have first made an ATB bar for the whole party. just now to figure for each one.
 
Well, you need to integrate the block I posted before in your main update loop. As for waiting in general, look at the default battle system: It uses a @wait variable (that might be called something different) and will when above 0 do nothing else than hold the script for that many frames. That's a very handy thing to spice up your battles, as timing is something very important.
 
Here's the formula:
@x += ((@gx - @x) / (@time))

x is the x-coordinate of the battler
gx is the x-coordinate of the target
(@gx - @x) is the formula used to get the x distance between the target and the battler's current position.
time is the duration of the movement.

Now, I have a problem:
The battler does go toward the target, but the final coordinate the battler is when it stops it is less than the one assigned, and i have already tested it to see that.

ipmeqt.png
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top