Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>def update(self):</p> <pre><code> self.speed.y -= GRAVITY displacement = Vec2d( self.direction.x * self.speed.x, self.direction.y * self.speed.y ) self.pos += displacement </code></pre> </blockquote> <p>You call Dot.update() 50 times every second. The equation you're using, </p> <pre><code>delta v_y = - g #* (1 second) </code></pre> <p>represents the change in velocity <strong>every second</strong>, but it gets called 50 times every second. This means your velocities will lose <code>50*GRAVITY m/s</code> ever second and this is why you are forced to make your gravity so weak. </p> <p>So, I would recommend adding <code>time_passed</code> as an argument for <code>Dot.update</code>, and change the speed changing statement to</p> <pre><code>def update(self, time_passed): self.speed.y -= GRAVITY * time_passed/1000. #time converted from millisecond to seconds </code></pre> <p>This will make the units more intuitive. Switch <code>GRAVITY</code> back to 10 and use realistic velocities. </p> <p><strong>EDIT:</strong></p> <p>Additionally, the displacement vector also needs to contain time, or else the displacement will depend on FPS. If you have <code>x</code> frames per second, then each update occurs after <code>t = 1000/x</code> milliseconds. This is the amount of time Dot spends "moving" in each update. Think about how we approximate Dot's motion; it gets an update, calculates its new velocity and travels at that speed for <code>t</code> seconds. However, in your implementation, the displacement vector is independent of time. Change the update method to be something like:</p> <pre><code>def update(self, time): time /= 1000. self.speed.y -= GRAVITY * time displacement = Vec2d( self.direction.x * self.speed.x * time, self.direction.y * self.speed.y * time ) self.pos += displacement </code></pre> <p>Now, according to kinematics, we'll get something like </p> <pre><code>max height = v0**2 / 2g </code></pre> <p>so initial velocities of 10-20m/s will only produce max heights of 5-20m. If you don't want to work with velocities of 50-200m/s, then you could add a scaling factor in the displacement vector, something like </p> <pre><code> displacement = Vec2d( self.direction.x * self.speed.x * time * scaling_factor, self.direction.y * self.speed.y * time * scaling_factor ) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload