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

Author Topic: Some Questions From a Beginner  (Read 964 times)

0 Members and 1 Guest are viewing this topic.

XoxoXFunkyXoxoX

  • Newbie
  • *
  • Posts: 2
    • View Profile
Some Questions From a Beginner
« on: April 12, 2017, 11:08:42 am »
Hi! I'm really new in SFML and I am trying to make a shooting game wherein the player could only move left and right along a curve. And there is an automatic shooting ability that follows the normal of the position where the player is currently staying. Just a few questions...

1. I was able to draw the curve and the tangent line but I don't know how to make the player move along the curve when I press the left and right arrow key
2. How do you make the player face the normal line  and shoot in that direction?

Sorry for all the questions, I just started studying SFML :)
« Last Edit: April 12, 2017, 12:59:55 pm by XoxoXFunkyXoxoX »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10845
    • View Profile
    • development blog
    • Email
Re: Some Questions From a Beginner
« Reply #1 on: April 12, 2017, 01:15:01 pm »
For movement you just use the data that was used to draw the curve for knowing where to place the entity next.
If the data is a function, you just calculate the next step, e.g. f(cur_pos + velocity * dt), where cur_pos is the current position vector, velocity is the velocity vector and dt is the delta time, i.e. frame time (the time a single grame takes to draw).
If it's a list of points, you'll have to take the distance between each point, thrn calculate how far you get (velocity * dt) and then find out where between the points you have to place your entity.

As for the rotation towards the normal, you'll most likely want to use atan2(). Google a bit and you should find lots of answers to that question. :)

Edit: Just realized, while the first idea works, it won't move uniformly on the curve but instead will move uniformly parallel to the x axis. Not exactly sure from the top of my head, but I think one could counter this somehow by using the derived function.
« Last Edit: April 12, 2017, 01:21:47 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

XoxoXFunkyXoxoX

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Some Questions From a Beginner
« Reply #2 on: April 12, 2017, 01:44:39 pm »
Hi thanks for answering! For the velocity, is that the per step (like the ratio of division) in a bezier curve?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10845
    • View Profile
    • development blog
    • Email
Re: Some Questions From a Beginner
« Reply #3 on: April 12, 2017, 02:18:19 pm »
Depends now on the approach you're using. How to you get the curve?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything