Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
minetest_game
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
minetest_game
Commits
454e0da5
Commit
454e0da5
authored
7 years ago
by
SmallJoker
Committed by
paramat
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Carts: Better wiggle prevention
parent
5870fd48
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mods/carts/cart_entity.lua
+20
-24
20 additions, 24 deletions
mods/carts/cart_entity.lua
with
20 additions
and
24 deletions
mods/carts/cart_entity.lua
+
20
−
24
View file @
454e0da5
...
...
@@ -43,16 +43,12 @@ function cart_entity:on_activate(staticdata, dtime_s)
if
data
.
old_dir
then
self
.
old_dir
=
data
.
old_dir
end
if
data
.
old_vel
then
self
.
old_vel
=
data
.
old_vel
end
end
function
cart_entity
:
get_staticdata
()
return
minetest
.
serialize
({
railtype
=
self
.
railtype
,
old_dir
=
self
.
old_dir
,
old_vel
=
self
.
old_vel
old_dir
=
self
.
old_dir
})
end
...
...
@@ -180,21 +176,11 @@ local function rail_on_step(self, dtime)
end
local
pos
=
self
.
object
:
get_pos
()
local
cart_dir
=
carts
:
velocity_to_dir
(
vel
)
local
same_dir
=
vector
.
equals
(
cart_dir
,
self
.
old_dir
)
local
update
=
{}
-- stop cart if velocity vector flips
if
self
.
old_vel
and
self
.
old_vel
.
y
==
0
and
(
self
.
old_vel
.
x
*
vel
.
x
<
0
or
self
.
old_vel
.
z
*
vel
.
z
<
0
)
then
self
.
old_vel
=
{
x
=
0
,
y
=
0
,
z
=
0
}
self
.
old_pos
=
pos
self
.
object
:
set_velocity
(
vector
.
new
())
self
.
object
:
set_acceleration
(
vector
.
new
())
rail_on_step_event
(
get_railparams
(
pos
).
on_step
,
self
,
dtime
)
return
end
self
.
old_vel
=
vector
.
new
(
vel
)
if
self
.
old_pos
and
not
self
.
punched
then
if
self
.
old_pos
and
not
self
.
punched
and
same_dir
then
local
flo_pos
=
vector
.
round
(
pos
)
local
flo_old
=
vector
.
round
(
self
.
old_pos
)
if
vector
.
equals
(
flo_pos
,
flo_old
)
then
...
...
@@ -213,7 +199,8 @@ local function rail_on_step(self, dtime)
end
end
if
self
.
old_pos
then
local
stop_wiggle
=
false
if
self
.
old_pos
and
same_dir
then
-- Detection for "skipping" nodes
local
found_path
=
carts
:
pathfinder
(
pos
,
self
.
old_pos
,
self
.
old_dir
,
ctrl
,
self
.
old_switch
,
self
.
railtype
...
...
@@ -224,9 +211,11 @@ local function rail_on_step(self, dtime)
pos
=
vector
.
new
(
self
.
old_pos
)
update
.
pos
=
true
end
elseif
self
.
old_pos
and
cart_dir
.
y
~=
-
1
and
not
self
.
punched
then
-- Stop wiggle
stop_wiggle
=
true
end
local
cart_dir
=
carts
:
velocity_to_dir
(
vel
)
local
railparams
-- dir: New moving direction of the cart
...
...
@@ -236,9 +225,16 @@ local function rail_on_step(self, dtime)
)
local
new_acc
=
{
x
=
0
,
y
=
0
,
z
=
0
}
if
vector
.
equals
(
dir
,
{
x
=
0
,
y
=
0
,
z
=
0
})
then
if
stop_wiggle
or
vector
.
equals
(
dir
,
{
x
=
0
,
y
=
0
,
z
=
0
})
then
vel
=
{
x
=
0
,
y
=
0
,
z
=
0
}
pos
=
vector
.
round
(
pos
)
local
pos_r
=
vector
.
round
(
pos
)
if
not
carts
:
is_rail
(
pos_r
,
self
.
railtype
)
then
pos
=
self
.
old_pos
elseif
not
stop_wiggle
then
pos
=
pos_r
else
pos
.
y
=
math.floor
(
pos
.
y
+
0
.
5
)
end
update
.
pos
=
true
update
.
vel
=
true
else
...
...
@@ -296,7 +292,7 @@ local function rail_on_step(self, dtime)
self
.
object
:
set_acceleration
(
new_acc
)
self
.
old_pos
=
vector
.
new
(
pos
)
if
not
vector
.
equals
(
dir
,
{
x
=
0
,
y
=
0
,
z
=
0
})
then
if
not
vector
.
equals
(
dir
,
{
x
=
0
,
y
=
0
,
z
=
0
})
and
not
stop_wiggle
then
self
.
old_dir
=
vector
.
new
(
dir
)
end
self
.
old_switch
=
switch_keys
...
...
@@ -332,7 +328,7 @@ local function rail_on_step(self, dtime)
elseif
self
.
old_dir
.
z
<
0
then
yaw
=
1
end
self
.
object
:
setyaw
(
yaw
*
math.pi
)
self
.
object
:
set
_
yaw
(
yaw
*
math.pi
)
local
anim
=
{
x
=
0
,
y
=
0
}
if
dir
.
y
==
-
1
then
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment