Skip to content

Commit

Permalink
0.8.2 - Add 2-stick input. Fix layers
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelAsherRivello committed Apr 26, 2024
1 parent 1d581a2 commit 835cde3
Show file tree
Hide file tree
Showing 58 changed files with 400 additions and 243 deletions.
2 changes: 1 addition & 1 deletion RMC DOTS/Samples~/RMC DOTS Game Samples.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,29 @@ public void OnCreate(ref SystemState state)
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
float2 inputComponentMove = SystemAPI.GetSingleton<InputComponent>().Move;
// First get the current input value from the PlayerMoveInput component. This component is set in the
// GetPlayerInputSystem that runs earlier in the frame.
float2 move = SystemAPI.GetSingleton<InputComponent>().Move;
float2 look = SystemAPI.GetSingleton<InputComponent>().Look;
float deltaTime = SystemAPI.Time.DeltaTime;

float2 moveComposite = float2.zero;

// Here we support EITHER look or move to move around
// Prioritize MOVE, if no MOVE is set, then use look
if (move.y != 0)
{
moveComposite.y = move.y;
}
else
{
moveComposite.y = look.y;
}

foreach (var (velocity, mass, paddleMoveComponent) in
SystemAPI.Query<RefRW<PhysicsVelocity>,PhysicsMass, PaddleMoveComponent>().WithAll<PaddleHumanTag>())
{
// Only move in the y
float currentMoveInput = inputComponentMove.y * paddleMoveComponent.Value * deltaTime;
float currentMoveInput = moveComposite.y * paddleMoveComponent.Value * deltaTime;
velocity.ValueRW.Linear.y = velocity.ValueRW.Linear.x + currentMoveInput;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Unity.Entities;
using Unity.Physics;
using UnityEngine;

namespace RMC.DOTS.Samples.Pong2D.Pong2D_Version02_DOTS
Expand Down Expand Up @@ -36,8 +35,4 @@ public override void Bake(PaddleMoveAuthoring authoring)
AddComponent(entity, new PaddleMoveComponent { Value = authoring.Speed });
}
}

public class FixedList128<T>
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@ public bool IsEnabledSimulationSystemGroup
// Unity Methods --------------------------------
protected async void Start()
{
//Make sure the project has layers set properly
var projectileName = "Projectile";
var projectileIndexCurrent = LayerMask.NameToLayer(projectileName);
var projectileIndexRequired = 8;

if (projectileIndexCurrent != projectileIndexRequired)
{
Debug.Log($"LayerMask failed. Must set Layer {projectileIndexRequired} to be '{projectileName}'.");
}

var goalName = "Goal";
var goalIndexCurrent = LayerMask.NameToLayer(goalName);
var goalIndexRequired = 9;

if (goalIndexCurrent != goalIndexRequired)
{
Debug.Log($"LayerMask failed. Must set Layer {goalIndexRequired} to be '{goalName}'.");
}

// ECS
_ecsWorld = await DOTSUtility.GetWorldAsync(_subScene);

// Game State
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,36 @@ public void OnUpdate(ref SystemState state)
{
// First get the current input value from the PlayerMoveInput component. This component is set in the
// GetPlayerInputSystem that runs earlier in the frame.
float2 inputComponentMove = SystemAPI.GetSingleton<InputComponent>().Move;
float2 move = SystemAPI.GetSingleton<InputComponent>().Move;
float2 look = SystemAPI.GetSingleton<InputComponent>().Look;
float deltaTime = SystemAPI.Time.DeltaTime;
float2 moveComposite = float2.zero;

// Here we support EITHER look or move to move around
// Prioritize MOVE, if no MOVE is set, then use look
if (move.x != 0)
{
moveComposite.x = move.x;
}
else
{
moveComposite.x = look.x;
}

// Although there is only one player in the game world, we still define systems as if we were executing over
// a group of players. Inside this idiomatic foreach, we apply force to the player based off the current
// move input and the force strength.
foreach (var (velocity, mass, moveForce) in
if (move.y != 0)
{
moveComposite.y = move.y;
}
else
{
moveComposite.y = look.y;
}

foreach (var (physicsVelocity, mass, playerMoveComponent) in
SystemAPI.Query<RefRW<PhysicsVelocity>,PhysicsMass, PlayerMoveComponent>().WithAll<PlayerTag>())
{
float3 moveInput3d = new float3(inputComponentMove.x, 0f, inputComponentMove.y);
float3 currentMoveInput = moveInput3d * moveForce.Value * deltaTime;
velocity.ValueRW.ApplyLinearImpulse(in mass, currentMoveInput);
float3 moveComposite3D = new float3(moveComposite.x, 0f, moveComposite.y) * (deltaTime * playerMoveComponent.Value);
physicsVelocity.ValueRW.ApplyLinearImpulse(in mass, moveComposite3D);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@ public bool IsEnabledSimulationSystemGroup
// Unity Methods --------------------------------
protected async void Start()
{
//Make sure the project has layers set properly
var playerName = "Player";
var playerIndexCurrent = LayerMask.NameToLayer(playerName);
var playerIndexRequired = 6;

if (playerIndexCurrent != playerIndexRequired)
{
Debug.Log($"LayerMask failed. Must set Layer {playerIndexRequired} to be '{playerName}'.");
}

var pickupName = "Pickup";
var pickupIndexCurrent = LayerMask.NameToLayer(pickupName);
var pickupIndexRequired = 7;

if (pickupIndexCurrent != pickupIndexRequired)
{
Debug.Log($"LayerMask failed. Must set Layer {pickupIndexRequired} to be '{pickupName}'.");
}

// ECS
_ecsWorld = await DOTSUtility.GetWorldAsync(_subScene);

// Game State
Expand Down
2 changes: 1 addition & 1 deletion RMC DOTS/Samples~/RMC DOTS Game Templates.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 835cde3

Please sign in to comment.