<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>http://digida.mgpu.ru/index.php?action=history&amp;feed=atom&amp;title=How_to_Make_a_Physics_Engine</id>
	<title>How to Make a Physics Engine - История изменений</title>
	<link rel="self" type="application/atom+xml" href="http://digida.mgpu.ru/index.php?action=history&amp;feed=atom&amp;title=How_to_Make_a_Physics_Engine"/>
	<link rel="alternate" type="text/html" href="http://digida.mgpu.ru/index.php?title=How_to_Make_a_Physics_Engine&amp;action=history"/>
	<updated>2026-05-31T01:44:03Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>http://digida.mgpu.ru/index.php?title=How_to_Make_a_Physics_Engine&amp;diff=2739&amp;oldid=prev</id>
		<title>Patarakin в 09:03, 5 сентября 2022</title>
		<link rel="alternate" type="text/html" href="http://digida.mgpu.ru/index.php?title=How_to_Make_a_Physics_Engine&amp;diff=2739&amp;oldid=prev"/>
		<updated>2022-09-05T09:03:53Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Предыдущая версия&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Версия от 12:03, 5 сентября 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l203&quot;&gt;Строка 203:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Строка 203:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Scripting Tutorials]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Scripting Tutorials]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Physics Tutorials]]&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Patarakin</name></author>
	</entry>
	<entry>
		<id>http://digida.mgpu.ru/index.php?title=How_to_Make_a_Physics_Engine&amp;diff=1762&amp;oldid=prev</id>
		<title>Patarakin: 1 версия импортирована</title>
		<link rel="alternate" type="text/html" href="http://digida.mgpu.ru/index.php?title=How_to_Make_a_Physics_Engine&amp;diff=1762&amp;oldid=prev"/>
		<updated>2022-07-21T08:33:16Z</updated>

		<summary type="html">&lt;p&gt;1 версия импортирована&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Предыдущая версия&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Версия от 11:33, 21 июля 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Patarakin</name></author>
	</entry>
	<entry>
		<id>http://digida.mgpu.ru/index.php?title=How_to_Make_a_Physics_Engine&amp;diff=1761&amp;oldid=prev</id>
		<title>scratch&gt;TemplatesFTW: Automated edit: fixed 2 style guidelines</title>
		<link rel="alternate" type="text/html" href="http://digida.mgpu.ru/index.php?title=How_to_Make_a_Physics_Engine&amp;diff=1761&amp;oldid=prev"/>
		<updated>2021-03-31T18:13:54Z</updated>

		<summary type="html">&lt;p&gt;Automated edit: fixed 2 style guidelines&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This tutorial shows how to make a simple physics engine where the sprite is not controlled by the arrow keys, as in [[Platformer]]s, but rather interacts like dropping and pushing the [[Sprite]] in real life would.&lt;br /&gt;
&lt;br /&gt;
== Make Variables ==&lt;br /&gt;
First make the following [[Variables]] &amp;#039;for this sprite&amp;#039;&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
(X Velocity)//The velocity of the sprite on the X axis&lt;br /&gt;
(Y Velocity)//The velocity of the sprite on the Y axis&lt;br /&gt;
(Direction::variables)//The speed at which the sprite is turning&lt;br /&gt;
(Slope)//Used for slope detection in collisions&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
Next make two sprites, one will be the one that uses the physics, and the other will be the one will be the ground that the sprite interacts with. In this tutorial, all the scripts are used in the main sprite and the ground sprite is called &amp;#039;ground&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
== Collision Detection ==&lt;br /&gt;
First, collision detection needs to be made. The collision detection that will be used is similar to ones used in platformers, however, this script does not use any controls to move the player.&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
define Physics (friction) (stiffness)//Run without screen refresh&lt;br /&gt;
if &amp;lt;not&amp;lt;touching (ground v)?&amp;gt;&amp;gt; then&lt;br /&gt;
    change [Y velocity v] by (-1)&lt;br /&gt;
end&lt;br /&gt;
change y by (Y velocity)&lt;br /&gt;
if &amp;lt;touching (ground v)?&amp;gt; then&lt;br /&gt;
    repeat ([abs v] of ([ceiling v] of (Y velocity)))&lt;br /&gt;
        change y by ((([abs v] of (Y velocity))/(Y velocity)) * (-1))&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
set [Y velocity v] to (1)&lt;br /&gt;
change x by (X Velocity)&lt;br /&gt;
if &amp;lt;touching (ground v)?&amp;gt; then&lt;br /&gt;
    set [slope v] to (0)&lt;br /&gt;
    repeat until &amp;lt;&amp;lt;(slope) = (-8)&amp;gt; or &amp;lt;not&amp;lt;touching (ground v)?&amp;gt;&amp;gt;&lt;br /&gt;
        change [slope v] by (-1)&lt;br /&gt;
        change y by (1)&lt;br /&gt;
    end&lt;br /&gt;
if &amp;lt;(slope) = (-8)&amp;gt; then&lt;br /&gt;
    change y by (slope)&lt;br /&gt;
    repeat ([abs v] of ([ceiling v] of (X Velocity)))&lt;br /&gt;
        change x by ((([abs v] of (X Velocity))/ (x Velocity))*(-1)&lt;br /&gt;
    end&lt;br /&gt;
    set [X Velocity v] to (0)&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Turning When Hitting a Slope ==&lt;br /&gt;
This script will make the sprite fall toward the ground and not go through it, however, this does not give a realistic physics look because the sprite does not turn or move on slopes. To add turning and sliding down slopes, another custom block needs to be made, called Turn:&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
define Turn//Run without screen rfefresh&lt;br /&gt;
change x by (10)//Move to the right and detect if still touching the ground, if not, turn and slide to the right a little bit.&lt;br /&gt;
if &amp;lt;not&amp;lt;touching (ground v)?&amp;gt;&amp;gt; then&lt;br /&gt;
    change [Direction v] by (3)&lt;br /&gt;
    change [X Velocity v] by (.3)&lt;br /&gt;
end&lt;br /&gt;
change x by (-20)//-20 this time because it is now needed to undo the movement from moving to the right and then move to the left, so the equivalent of moving to the left twice.&lt;br /&gt;
if &amp;lt;not&amp;lt;touching (ground v) ?&amp;gt;&amp;gt; then//Do the opposite this time.&lt;br /&gt;
    change [Direction v] by (-3)&lt;br /&gt;
    change [X Velocity v] by (-.3)&lt;br /&gt;
end&lt;br /&gt;
change x by (10)&lt;br /&gt;
turn cw (2) degrees&lt;br /&gt;
if &amp;lt;not&amp;lt;touching (ground v)?&amp;gt;&amp;gt; then&lt;br /&gt;
    change [Direction v] by (1)&lt;br /&gt;
end&lt;br /&gt;
turn ccw (4) degrees&lt;br /&gt;
if &amp;lt;not&amp;lt;touching (ground v)?&amp;gt;&amp;gt; then&lt;br /&gt;
    change [Direction v] by (-1)&lt;br /&gt;
end&lt;br /&gt;
turn cw (12) degrees&lt;br /&gt;
if &amp;lt;not&amp;lt;touching (ground v)?&amp;gt;&amp;gt; then&lt;br /&gt;
    change [Direction v] by (2)&lt;br /&gt;
end&lt;br /&gt;
turn ccw (20) degrees&lt;br /&gt;
if &amp;lt;not&amp;lt;touching (ground v)?&amp;gt;&amp;gt; then&lt;br /&gt;
    change [Direction v] by (-2)&lt;br /&gt;
end&lt;br /&gt;
turn cw (10) degrees&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now that the turning custom block has been created, it needs to be used:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
define Physics (friction) (stiffness)//Run without screen refresh&lt;br /&gt;
if &amp;lt;not&amp;lt;touching (ground v)?&amp;gt;&amp;gt; then&lt;br /&gt;
    change [Y velocity v] by (-1)&lt;br /&gt;
end&lt;br /&gt;
change y by (Y velocity)&lt;br /&gt;
if &amp;lt;touching (ground v)?&amp;gt; then&lt;br /&gt;
    repeat ([abs v] of ([ceiling v] of (Y velocity)))&lt;br /&gt;
        change y by ((([abs v] of (Y velocity))/(Y velocity)) * (-1))&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
set [Y velocity v] to (1)&lt;br /&gt;
change x by (X Velocity)&lt;br /&gt;
if &amp;lt;touching (ground v)?&amp;gt; then&lt;br /&gt;
    set [slope v] to (0)&lt;br /&gt;
    repeat until &amp;lt;&amp;lt;(slope) = (-8)&amp;gt; or &amp;lt;not&amp;lt;touching (ground v)?&amp;gt;&amp;gt;&lt;br /&gt;
        change [slope v] by (-1)&lt;br /&gt;
        change y by (1)&lt;br /&gt;
    end&lt;br /&gt;
if &amp;lt;(slope) = (-8)&amp;gt; then&lt;br /&gt;
    change y by (slope)&lt;br /&gt;
    repeat ([abs v] of ([ceiling v] of (X Velocity)))&lt;br /&gt;
        change x by ((([abs v] of (X Velocity))/ (x Velocity))*(-1)&lt;br /&gt;
    end&lt;br /&gt;
    set [X Velocity v] to (0)&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
turn cw (Direction::variables) degrees&lt;br /&gt;
set [Direction v] to ((Direction::variables) * (stiffness::custom))&lt;br /&gt;
set [X Velocity v] to ((X velocity) * (friction::custom))&lt;br /&gt;
Turn::custom&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Implementing Code==&lt;br /&gt;
The turning and collision detection has been created, so the only thing left to do is to use it.&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
When green flag clicked&lt;br /&gt;
go to x: (0) y: (0)//Where the sprite will start (coordinates can be different)&lt;br /&gt;
set [Direction v] to [0]//Setting variables to avoid bugs&lt;br /&gt;
set [X Velocity v] to [0]&lt;br /&gt;
set [Y Velocity v] to [0]&lt;br /&gt;
forever//using our code!&lt;br /&gt;
    Physics (0.95)(.6)::custom&lt;br /&gt;
    ...::grey//Other code can be placed in here for the controls of the sprite, e.g. allow it to be dragged, moved by the arrow keys, etc.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Final Code ==&lt;br /&gt;
{{note|Make sure to check the code for any bugs that may be encountered.}}&lt;br /&gt;
Here is the final code for the physics engine:&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
define Physics (friction) (stiffness)//Run without screen refresh&lt;br /&gt;
if &amp;lt;not&amp;lt;touching (ground v)?&amp;gt;&amp;gt; then&lt;br /&gt;
    change [Y velocity v] by (-1)&lt;br /&gt;
end&lt;br /&gt;
change y by (Y velocity)&lt;br /&gt;
if &amp;lt;touching (ground v)?&amp;gt; then&lt;br /&gt;
    repeat ([abs v] of ([ceiling v] of (Y velocity)))&lt;br /&gt;
        change y by ((([abs v] of (Y velocity))/(Y velocity)) * (-1))&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
set [Y velocity v] to (1)&lt;br /&gt;
change x by (X Velocity)&lt;br /&gt;
if &amp;lt;touching (ground v)?&amp;gt; then&lt;br /&gt;
    set [slope v] to (0)&lt;br /&gt;
    repeat until &amp;lt;&amp;lt;(slope) = (-8)&amp;gt; or &amp;lt;not&amp;lt;touching (ground v)?&amp;gt;&amp;gt;&lt;br /&gt;
        change [slope v] by (-1)&lt;br /&gt;
        change y by (1)&lt;br /&gt;
    end&lt;br /&gt;
if &amp;lt;(slope) = (-8)&amp;gt; then&lt;br /&gt;
    change y by (slope)&lt;br /&gt;
    repeat ([abs v] of ([ceiling v] of (X Velocity)))&lt;br /&gt;
        change x by ((([abs v] of (X Velocity))/ (x Velocity))*(-1)&lt;br /&gt;
    end&lt;br /&gt;
    set [X Velocity v] to (0)&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
turn cw (Direction::variables) degrees&lt;br /&gt;
set [Direction v] to ((Direction::variables) * (stiffness::custom))&lt;br /&gt;
set [X Velocity v] to ((X velocity) * (friction::custom))&lt;br /&gt;
Turn::custom&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
define Turn//Run without screen rfefresh&lt;br /&gt;
change x by (10)//Move to the right and detect if still touching the ground, if not, turn and slide to the right a little bit.&lt;br /&gt;
if &amp;lt;not&amp;lt;touching (ground v)?&amp;gt;&amp;gt; then&lt;br /&gt;
    change [Direction v] by (3)&lt;br /&gt;
    change [X Velocity v] by (.3)&lt;br /&gt;
end&lt;br /&gt;
change x by (-20)//-20 this time because it is now needed to undo the movement from moving to the right and then move to the left, so the equivalent of moving to the left twice.&lt;br /&gt;
if &amp;lt;not&amp;lt;touching (ground v) ?&amp;gt;&amp;gt; then//Do the opposite this time.&lt;br /&gt;
    change [Direction v] by (-3)&lt;br /&gt;
    change [X Velocity v] by (-.3)&lt;br /&gt;
end&lt;br /&gt;
change x by (10)&lt;br /&gt;
turn cw (2) degrees&lt;br /&gt;
if &amp;lt;not&amp;lt;touching (ground v)?&amp;gt;&amp;gt; then&lt;br /&gt;
    change [Direction v] by (1)&lt;br /&gt;
end&lt;br /&gt;
turn ccw (4) degrees&lt;br /&gt;
if &amp;lt;not&amp;lt;touching (ground v)?&amp;gt;&amp;gt; then&lt;br /&gt;
    change [Direction v] by (-1)&lt;br /&gt;
end&lt;br /&gt;
turn cw (12) degrees&lt;br /&gt;
if &amp;lt;not&amp;lt;touching (ground v)?&amp;gt;&amp;gt; then&lt;br /&gt;
    change [Direction v] by (2)&lt;br /&gt;
end&lt;br /&gt;
turn ccw (20) degrees&lt;br /&gt;
if &amp;lt;not&amp;lt;touching (ground v)?&amp;gt;&amp;gt; then&lt;br /&gt;
    change [Direction v] by (-2)&lt;br /&gt;
end&lt;br /&gt;
turn cw (10) degrees&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When green flag clicked&lt;br /&gt;
go to x: (0) y: (0)//Where the sprite will start (coordinates can be different)&lt;br /&gt;
set [Direction v] to [0]//Setting variables to avoid bugs&lt;br /&gt;
set [X Velocity v] to [0]&lt;br /&gt;
set [Y Velocity v] to [0]&lt;br /&gt;
forever&lt;br /&gt;
    Physics (0.95)(.6)::custom&lt;br /&gt;
    ...::grey//Other code can be placed in here for the controls of the sprite, e.g. allow it to be dragged, moved by the arrow keys, etc.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripting Tutorials]]&lt;br /&gt;
[[Category:Physics Tutorials]]&lt;/div&gt;</summary>
		<author><name>scratch&gt;TemplatesFTW</name></author>
	</entry>
</feed>