Sonic and Sega Retro Message Board: Trying to implement physics from the Sonic Physics Guide... issue - Sonic and Sega Retro Message Board

Jump to content

Hey there, Guest!  (Log In · Register) Help
Page 1 of 1
    Locked
    Locked Forum

Trying to implement physics from the Sonic Physics Guide... issue Feel like a complete blooming idiot.

#1 User is offline Travelsonic 

Posted 06 October 2013 - 02:41 PM

  • Posts: 661
  • Joined: 01-March 05
As the topic description says, I feel like a complete blooming idiot right now.

For fun I wanted to see if I could implement the physics as describe in the physics guide in a Megadrive era Sonic engine of my own using C++.

I made Sonic his own class. In the Sonic class, I have friction, max speed, acceleration, and deacceleration set up pre-defined [but not as constants, as underwater ALL OF these values are different if I recall correctly]. For movement, I have a function that takes in an integer representing the key pressed, allowing me to keep the class independent of the graphics/gaming libraries I am using for longer during testing.

[Basically, the "if the player is pressing left," " if the player is pressing right" is now down to a switch statement based on the integer passed as an argument]

The function then checks that code, and for left/right movement, handles it exactly like it was laid out in the guide for when Sonic is running on a flat surface:

the physics guide said:


if the player is pressing left
{
if X speed > 0
{
X speed -= dec
}
else
if X speed > -max
{
X speed = X speed - acc
}
else X speed = -max
}
else
if the player is pressing right
{
if X speed < 0
{
X speed += dec
}
else
if X speed < max
{
X speed = X speed + acc
}
else X speed = max
}
}



Only not pseudo code, of course, and with an additional condition where if the X speed is 0 then it adds [if moving right] or subtracts [if moving left] the acceleration, and if nothing is being pressed, the friction is applied appropriately.

Now the problem.

I wanted to test how, when implemented, how a change in X position would look [as opposed to just the X speed]. Like with the X speed being displayed on screen, I then made it so it also showed X position on screen, and I can't help but feel like I am doing something wrong, as the rate of change is absolutely insane.

Ugh.
This post has been edited by Travelsonic: 06 October 2013 - 02:45 PM

#2 User is online Morph 

Posted 06 October 2013 - 05:28 PM

  • AKA SonicFreak94.
  • Posts: 548
  • Joined: 01-August 08
  • Gender:Male
  • Location:Utah
  • Project:SA2 netplay & hax, SADX:FE
  • Wiki edits:11
Is it running above 60FPS without delta timing? Maybe a stupid suggestion, but if it's running at like, 300 frames per second, you're applying those changes at a rate of once per frame (about every 3ms at 300FPS, for example) without delta timing, and as you could probably guess, that means everything applies too quickly.

#3 User is offline JustinTU 

Posted 06 October 2013 - 08:06 PM

  • Posts: 5
  • Joined: 06-June 09
  • Gender:Male
  • Location:Montgomery, Alabama
  • Project:SADE Engine (C++)
Like Morph said, the values for the various properties of the player's movement are in terms of displacement per frame, so if your values are increasing or decreasing too fast, then you simply need to lock your frame rate or lock just the physics to a certain frame rate. There many ways to do it, some of which are inefficient and effect the smoothness of the gameplay. I would recommend taking a look at this guide (link). My own engine uses a modified version of the method described in that guide that works pretty well for me.

#4 User is offline Travelsonic 

Posted 07 October 2013 - 12:36 AM

  • Posts: 661
  • Joined: 01-March 05
Told you I feel like a blooming idiot. The framerate... fuck me....

For the time being, I merely moved the decimal point over one place for each variable's value [accel, deaccel, friction, etc] and that made things work beautifully until I can be arsed enough to do a better tweak should I actually need to do better as I will be busy as hell on my Android app development and whatever else thrown my way from working for my 'rents. :argh:
This post has been edited by Travelsonic: 07 October 2013 - 12:48 AM

#5 User is offline winterhell 

Posted 07 October 2013 - 02:47 AM

  • Posts: 747
  • Joined: 16-October 10
  • Gender:Male
Can you just slap something like Sleep(14) for the time being? That'd stabilize your fps. Or activate vSync.

#6 User is offline Travelsonic 

Posted 26 October 2013 - 01:57 PM

  • Posts: 661
  • Joined: 01-March 05
In the game loop I implemented some rest similar to what you, winterhell, suggested for the time being - works good now. :D

[Don't lock thread, powers-that-be, as I may still have plenty of questions going into all this.]

#7 User is offline kazade 

Posted 20 February 2014 - 02:23 AM

  • Posts: 64
  • Joined: 16-March 10
  • Project:A 2D Physics Engine

View PostTravelsonic, on 26 October 2013 - 01:57 PM, said:

In the game loop I implemented some rest similar to what you, winterhell, suggested for the time being - works good now. :D

[Don't lock thread, powers-that-be, as I may still have plenty of questions going into all this.]


In my engine I've multiplied each constant by 60 (e.g. the change per second) and then each update add the value multiplied by a delta time value. Seems to work great!

Page 1 of 1
    Locked
    Locked Forum

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users