Skip to content

Commit

Permalink
Reduced default physics density to 1.0f from 10.0f.
Browse files Browse the repository at this point in the history
Fixed bug in Elm property initialization not propagating physics.


Former-commit-id: 29775c8
  • Loading branch information
bryanedds committed Mar 28, 2020
1 parent 14c4980 commit 7a70660
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Nu/Nu.Template.Export/Nu.Game.zip.REMOVED.git-id
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a614717e0e76986fd9cbcae306630ae2f8aa7cfa
762c83694dc72e952380c4fbeac6ad0ead04a743
10 changes: 5 additions & 5 deletions Nu/Nu.Template/MyGameplay.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ type MyGameplayDispatcher () =
| Jump ->
let physicsId = Simulants.Player.GetPhysicsId world
if World.isBodyOnGround physicsId world then
let world = World.applyBodyForce (v2 0.0f 2000000.0f) physicsId world
let world = World.applyBodyForce (v2 0.0f 200000.0f) physicsId world
World.playSound 1.0f (asset "Gameplay" "Jump") world
else world
| MoveLeft ->
let physicsId = Simulants.Player.GetPhysicsId world
if World.isBodyOnGround physicsId world
then World.applyBodyForce (v2 -30000.0f 0.0f) physicsId world
else World.applyBodyForce (v2 -7500.0f 0.0f) physicsId world
then World.applyBodyForce (v2 -3000.0f 0.0f) physicsId world
else World.applyBodyForce (v2 -750.0f 0.0f) physicsId world
| MoveRight ->
let physicsId = Simulants.Player.GetPhysicsId world
if World.isBodyOnGround physicsId world
then World.applyBodyForce (v2 30000.0f 0.0f) physicsId world
else World.applyBodyForce (v2 7500.0f 0.0f) physicsId world
then World.applyBodyForce (v2 3000.0f 0.0f) physicsId world
else World.applyBodyForce (v2 750.0f 0.0f) physicsId world
| EyeTrack ->
if World.getTickRate world <> 0L
then Simulants.Game.SetEyeCenter (Simulants.Player.GetCenter world) world
Expand Down
2 changes: 1 addition & 1 deletion Nu/Nu/Constants.fs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module Constants =
let (*Literal*) PhysicsStepRate = 1.0f / single Engine.DesiredFps
let [<Literal>] PhysicsToPixelRatio = 64.0f
let (*Literal*) PixelToPhysicsRatio = 1.0f / PhysicsToPixelRatio
let [<Literal>] NormalDensity = 10.0f // NOTE: this seems to be a stable density for Farseer
let [<Literal>] NormalDensity = 1.0f
let (*Literal*) Gravity = Vector2 (0.0f, -9.80665f) * PhysicsToPixelRatio
let [<Literal>] CollisionProperty = "C"
let (*Literal*) MessageListConfig = Functional
Expand Down
8 changes: 2 additions & 6 deletions Nu/Nu/WorldEntity.fs
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,8 @@ module WorldEntityModule =
/// Propagate entity physics properties into the physics system.
member this.PropagatePhysics world =
World.withEventContext (fun world ->
if WorldModule.isSimulantSelected this world then
let facets = this.GetFacets world
Array.fold (fun world (facet : Facet) ->
let world = facet.UnregisterPhysics (this, world)
facet.RegisterPhysics (this, world))
world facets
if WorldModule.isSimulantSelected this world
then World.propagateEntityPhysics this world
else world)
this world

Expand Down
7 changes: 7 additions & 0 deletions Nu/Nu/WorldModuleEntity.fs
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,11 @@ module WorldModuleEntity =
Array.fold (fun world (facet : Facet) -> facet.UnregisterPhysics (entity, world)) world facets)
entity world

static member internal propagateEntityPhysics entity world =
let world = World.unregisterEntityPhysics entity world
let world = World.registerEntityPhysics entity world
world

static member internal addEntity mayReplace entityState entity world =

// add entity only if it is new or is explicitly able to be replaced
Expand Down Expand Up @@ -823,6 +828,8 @@ module WorldModuleEntity =
Map.fold (fun world propertyName property ->
World.setEntityProperty propertyName false false property entity world)
world descriptor.SimulantProperties
let world =
World.propagateEntityPhysics entity world
(entity, world)

/// Create an entity and add it to the world.
Expand Down
14 changes: 7 additions & 7 deletions Projects/BlazeVector/BlazeDispatchers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module BulletModule =
static member Properties =
[define Entity.Size (Vector2 (20.0f, 20.0f))
define Entity.Omnipresent true
define Entity.Density 0.25f
define Entity.Density 0.1f
define Entity.Restitution 0.5f
define Entity.LinearDamping 0.0f
define Entity.GravityScale 0.0f
Expand Down Expand Up @@ -72,7 +72,7 @@ module EnemyModule =
inherit EntityDispatcher ()

static let move (enemy : Entity) world =
let force = Vector2 (-2000.0f, -20000.0f)
let force = Vector2 (-250.0f, -2500.0f)
World.applyBodyForce force (enemy.GetPhysicsId world) world

static let die (enemy : Entity) world =
Expand Down Expand Up @@ -135,9 +135,9 @@ module PlayerModule =
type PlayerDispatcher () =
inherit EntityDispatcher ()

static let [<Literal>] WalkForce = 8000.0f
static let [<Literal>] FallForce = -30000.0f
static let [<Literal>] ClimbForce = 12000.0f
static let [<Literal>] WalkForce = 1000.0f
static let [<Literal>] FallForce = -4000.0f
static let [<Literal>] ClimbForce = 1500.0f

static let createBullet (player : Entity) (playerTransform : Transform) world =
let (bullet, world) = World.createEntity<BulletDispatcher> None DefaultOverlay player.Parent world
Expand All @@ -148,7 +148,7 @@ module PlayerModule =
(bullet, world)

static let propelBullet (bullet : Entity) world =
let world = World.applyBodyLinearImpulse (Vector2 (35.0f, 0.0f)) (bullet.GetPhysicsId world) world
let world = World.applyBodyLinearImpulse (Vector2 (15.0f, 0.0f)) (bullet.GetPhysicsId world) world
World.playSound 1.0f Assets.ShotSound world

static let shootBullet (player : Entity) world =
Expand Down Expand Up @@ -191,7 +191,7 @@ module PlayerModule =
if tickTime >= player.GetLastTimeJumpNp world + 12L &&
tickTime <= player.GetLastTimeOnGroundNp world + 10L then
let world = player.SetLastTimeJumpNp tickTime world
let world = World.applyBodyLinearImpulse (Vector2 (0.0f, 18000.0f)) (player.GetPhysicsId world) world
let world = World.applyBodyLinearImpulse (Vector2 (0.0f, 2000.0f)) (player.GetPhysicsId world) world
let world = World.playSound 1.0f Assets.JumpSound world
world
else world
Expand Down
10 changes: 5 additions & 5 deletions Projects/Elmario/Elmario.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ type ElmarioDispatcher () =
| MoveLeft ->
let physicsId = Simulants.Elmario.GetPhysicsId world
if World.isBodyOnGround physicsId world
then World.applyBodyForce (v2 -30000.0f 0.0f) physicsId world
else World.applyBodyForce (v2 -7500.0f 0.0f) physicsId world
then World.applyBodyForce (v2 -3000.0f 0.0f) physicsId world
else World.applyBodyForce (v2 -750.0f 0.0f) physicsId world
| MoveRight ->
let physicsId = Simulants.Elmario.GetPhysicsId world
if World.isBodyOnGround physicsId world
then World.applyBodyForce (v2 30000.0f 0.0f) physicsId world
else World.applyBodyForce (v2 7500.0f 0.0f) physicsId world
then World.applyBodyForce (v2 3000.0f 0.0f) physicsId world
else World.applyBodyForce (v2 750.0f 0.0f) physicsId world
| Jump ->
let physicsId = Simulants.Elmario.GetPhysicsId world
if World.isBodyOnGround physicsId world then
let world = World.applyBodyForce (v2 0.0f 2000000.0f) physicsId world
let world = World.applyBodyForce (v2 0.0f 200000.0f) physicsId world
World.playSound 0.5f (asset "Gameplay" "Jump") world
else world
| Nop -> world
Expand Down

0 comments on commit 7a70660

Please sign in to comment.