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

Author Topic: Questions about vehicle movement  (Read 1784 times)

0 Members and 1 Guest are viewing this topic.

iv-med

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Questions about vehicle movement
« on: May 26, 2015, 07:02:45 pm »
Hi to all!
I'm planning to create simple racing game, but there have been some difficulties associated with the movement of the vehicle:
1)how to make a front-wheel drive vehicle using SFML?
2)how to make a smooth braking car when you press the "down"?

I have attached the source code in an attachment.
I would be grateful for any help!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10838
    • View Profile
    • development blog
    • Email
Re: Questions about vehicle movement
« Reply #1 on: May 26, 2015, 08:20:11 pm »
It's your game, so you should be able to come up with the ideas and implementations not others.
If you have a specific question you can ask that, but no general "how do you do this".

Also I moved the post to the General Help forum, since the SFML Projects forum is for well SFML Projects and not help questions. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3353
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Questions about vehicle movement
« Reply #2 on: May 27, 2015, 01:45:04 am »
Does this help:
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
                {
                        if (movementVec == forwardVec)
                        {
                                currentSpeed -= deceleration * dt;
                                if (currentSpeed < 0.f)
                                        movementVec = reverseVec;
                        }
                        else
                        {
                                currentSpeed += acceleration * dt;
                                if (currentSpeed > maxSpeed)
                                        currentSpeed = maxSpeed;
                        }
                }

 8)


EDIT: Fixed typo
« Last Edit: May 27, 2015, 09:22:59 pm by Hapax »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: Questions about vehicle movement
« Reply #3 on: May 27, 2015, 10:59:02 am »
Should that be a single = on line 7?

Hapax

  • Hero Member
  • *****
  • Posts: 3353
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Questions about vehicle movement
« Reply #4 on: May 27, 2015, 09:23:07 pm »
Should that be a single = on line 7?
In my code? Yes, certainly should be. Corrected, thank you  :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

iv-med

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Questions about vehicle movement
« Reply #5 on: June 01, 2015, 10:47:59 am »
Does this help:
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
                {
                        if (movementVec == forwardVec)
                        {
                                currentSpeed -= deceleration * dt;
                                if (currentSpeed < 0.f)
                                        movementVec = reverseVec;
                        }
                        else
                        {
                                currentSpeed += acceleration * dt;
                                if (currentSpeed > maxSpeed)
                                        currentSpeed = maxSpeed;
                        }
                }

 8)


EDIT: Fixed typo

Hi!
You code is incorrect
When I press down my car moves forward :(

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Questions about vehicle movement
« Reply #6 on: June 01, 2015, 11:02:06 am »
The idea is not that you copy the code 1:1 and complain if it doesn't immediately work as expected. It should rather serve as a source of inspiration... As eXpl0it3r said, as a programmer you have to be able to come up with your own solutions.

If you struggle with implementing vehicle movement, maybe you should start with something simpler until you have the necessary experience? :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

iv-med

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Questions about vehicle movement
« Reply #7 on: June 01, 2015, 11:13:36 am »
The idea is not that you copy the code 1:1 and complain if it doesn't immediately work as expected. It should rather serve as a source of inspiration... As eXpl0it3r said, as a programmer you have to be able to come up with your own solutions.

If you struggle with implementing vehicle movement, maybe you should start with something simpler until you have the necessary experience? :)
Yes, you right.

 

anything