Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [Help] An Isometric Movement Code  (Read 1454 times)

0 Members and 1 Guest are viewing this topic.

TioMOG

  • Newbie
  • *
  • Posts: 5
  • Panthomime
    • View Profile
[Help] An Isometric Movement Code
« on: October 26, 2014, 09:34:22 pm »
Hey, guys!

You guys helped me in the last topic I made for a help in collision for my isometric race game (this one), and I thank you very much :D

But now I'm getting stuck by this one problem, that is implementing a acceleration factor in my game. The main problem is that, as it is an Isometric game, the "speed+acceleration" and "speed+deacceleration" aren't enough to create a smooth functional moviment.
My code, for now, it's like this:

This is the code to acelerate:
(click to show/hide)

This is the code to swith the sprite's frame (The spritesheet is attached to the topic, for a better interpretation):
(click to show/hide)

And here's a simpler code that I was using to represent the moviment, but without an acceleration factor:
(click to show/hide)

My game is based on an 90's race SNES game, Rock n' Roll Racing, so, the movement I'm trying to implement looks like .

My problem resides in two problems:
1. The acceleration is different for the X axis and the Y axis at the same time, as for the velocity varies from a negative top-speed to a positive top-speed (since the moviment is in 360º).
2. When my car rotates, the velocity in both axis have to change, but not in the same way (and I can't use a simple rotate method, since my car it's a spritesheet, and rotate it can bug the graphic).

My car rotate from the keys "Up" and "Down", and it's movement is triggered by the "Ctrl" key.
I've tried doing the basic "when speed is lower than tospeed, accelerate", but when the car changes the frame, it changes the top-speed, leading the car to keep the velocity equals to the top-speed of the frame that it was when the acceleration began.

I would be very grateful if you guys could help me trough this :)
Thanks, seeya o/
nah

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10914
    • View Profile
    • development blog
    • Email
AW: [Help] An Isometric Movement Code
« Reply #1 on: October 26, 2014, 10:20:58 pm »
A good practice is to keep your logic separated from your visual representation. I'm not sure how it will play out in the end, but for the math and physics it would simplify a lot.

Do the math in a simple 2D space (think top down view) and transform these values into your isometric space.

And no, nobody will be writing your code. Sit down with pen and paper and just think about what you want to achieve. Don't write code unless you're 100% sure how it should work.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

TioMOG

  • Newbie
  • *
  • Posts: 5
  • Panthomime
    • View Profile
Re: [Help] An Isometric Movement Code
« Reply #2 on: October 27, 2014, 03:15:54 am »
Sorry, but you missunderstood me. I have wrote several codes, and worked with several alternative logics. All I want from here is for a "light" to understand how to deal with the "sprite-changing problem". I really don't want a code just to copy it, since I'm working on this project for educational matters.

It's like this: I had a acceleration functionable code, working as the physic's logic. My problem was that my sprite don't rotate, it only changes the sprite's frame when a key Up or Down is pressed. I deal the rotation considerating that instance's frame as the angle the car. The deal with it was that when the player presses the key "Up" or "Down", the method that changes the sprite is active as long as the key is pressed, so the top-speed for that position of the frame doesn't change and the car will continue to speed like it haven't change the sprite, like a "drift". I'm okay with the car drifting, since it do it too in the original game, but my car drifts for as long as the key is pressed, resulting in cases when it is facing right and still moving left.
I tried to do a code that once the keys "Up" and "Down" are pressed when the "Ctrl" is pressed it would deaccelerate, but, for some reason I still don't know, it haven't work.
Right now I'm looking on this drifting code to see if I can reduce the drift time, that would considerably helps me to find a realistic movement.
nah