OnCollisionEnter doesn't trigger - unity3d

using UnityEngine;
using System.Collections;
public class changedirection : MonoBehaviour {
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "soldier")
{
GameObject go = col.gameObject;
Move move = go.GetComponent<Move>();
move.direction = -1;
}
}
}
Both objects that collide are triggers, sorry didn't program with unity for over a year

Static colliders don't collide with each other.
There was a table that showed when collision and trigger events are fired on docs.unity3d.com. But they have updated the site and now I can't find it. I still have it local. So, here it is.
Collision action matrix
Depending on the configurations of the two colliding Objects, a number of different actions can occur. The chart below outlines what you can expect from two colliding Objects, based on the components that are attached to them. Some of the combinations only cause one of the two Objects to be affected by the collision, so keep the standard rule in mind - physics will not be applied to objects that do not have Rigidbodies attached.
Collision detection occurs and messages are sent upon collision
╔═══════════╦══════════╤═══════════╤═══════════╤══════════╤═══════════╤═══════════╗
║ ║ Static │ Rigidbody │ Kinematic │ Static │ Rigidbody │ Kinematic ║
║ ║ Collider │ Collider │ Rigidbody │ Trigger │ Trigger │ Rigidbody ║
║ ║ │ │ Collider │ Collider │ Collider │ Trigger ║
║ ║ │ │ │ │ │ Collider ║
╠═══════════╬══════════╪═══════════╪═══════════╪══════════╪═══════════╪═══════════╣
║ Static ║ │ Y │ │ │ │ ║
║ Collider ║ │ │ │ │ │ ║
╟───────────╫──────────┼───────────┼───────────┼──────────┼───────────┼───────────╢
║ Rigidbody ║ Y │ Y │ Y │ │ │ ║
║ Collider ║ │ │ │ │ │ ║
╟───────────╫──────────┼───────────┼───────────┼──────────┼───────────┼───────────╢
║ Kinematic ║ │ Y │ │ │ │ ║
║ Rigidbody ║ │ │ │ │ │ ║
║ Collider ║ │ │ │ │ │ ║
╟───────────╫──────────┼───────────┼───────────┼──────────┼───────────┼───────────╢
║ Static ║ │ │ │ │ │ ║
║ Trigger ║ │ │ │ │ │ ║
║ Collider ║ │ │ │ │ │ ║
╟───────────╫──────────┼───────────┼───────────┼──────────┼───────────┼───────────╢
║ Rigidbody ║ │ │ │ │ │ ║
║ Trigger ║ │ │ │ │ │ ║
║ Collider ║ │ │ │ │ │ ║
╟───────────╫──────────┼───────────┼───────────┼──────────┼───────────┼───────────╢
║ Kinematic ║ │ │ │ │ │ ║
║ Rigidbody ║ │ │ │ │ │ ║
║ Trigger ║ │ │ │ │ │ ║
║ Collider ║ │ │ │ │ │ ║
╚═══════════╩══════════╧═══════════╧═══════════╧══════════╧═══════════╧═══════════╝
Trigger messages are sent upon collision
╔═══════════╦══════════╤═══════════╤═══════════╤══════════╤═══════════╤═══════════╗
║ ║ Static │ Rigidbody │ Kinematic │ Static │ Rigidbody │ Kinematic ║
║ ║ Collider │ Collider │ Rigidbody │ Trigger │ Trigger │ Rigidbody ║
║ ║ │ │ Collider │ Collider │ Collider │ Trigger ║
║ ║ │ │ │ │ │ Collider ║
╠═══════════╬══════════╪═══════════╪═══════════╪══════════╪═══════════╪═══════════╣
║ Static ║ │ │ │ │ Y │ Y ║
║ Collider ║ │ │ │ │ │ ║
╟───────────╫──────────┼───────────┼───────────┼──────────┼───────────┼───────────╢
║ Rigidbody ║ │ │ │ Y │ Y │ Y ║
║ Collider ║ │ │ │ │ │ ║
╟───────────╫──────────┼───────────┼───────────┼──────────┼───────────┼───────────╢
║ Kinematic ║ │ │ │ │ │ ║
║ Rigidbody ║ │ │ │ Y │ Y │ Y ║
║ Collider ║ │ │ │ │ │ ║
╟───────────╫──────────┼───────────┼───────────┼──────────┼───────────┼───────────╢
║ Static ║ │ │ │ │ │ ║
║ Trigger ║ │ Y │ Y │ │ Y │ Y ║
║ Collider ║ │ │ │ │ │ ║
╟───────────╫──────────┼───────────┼───────────┼──────────┼───────────┼───────────╢
║ Rigidbody ║ │ │ │ │ │ ║
║ Trigger ║ Y │ Y │ Y │ Y │ Y │ Y ║
║ Collider ║ │ │ │ │ │ ║
╟───────────╫──────────┼───────────┼───────────┼──────────┼───────────┼───────────╢
║ Kinematic ║ │ │ │ │ │ ║
║ Rigidbody ║ Y │ Y │ Y │ Y │ Y │ Y ║
║ Trigger ║ │ │ │ │ │ ║
║ Collider ║ │ │ │ │ │ ║
╚═══════════╩══════════╧═══════════╧═══════════╧══════════╧═══════════╧═══════════╝
Layer-Based Collision Detection
In Unity 3.x we introduce something called Layer-Based Collision Detection, and you can now selectively tell Unity GameObjects to collide with specific layers they are attached to. For more information click here.

Related

Transposition using multiple merges (feedback wanted)

i have a solution in danfojs (codepen below) but would like some feedback on how to improve it, since im new to danfo, maybe the same result can be obtained more elegantly.
Essentially i want to do a transposition by merging around twenty Dataframes, but realized that the merge feature only allows to merge two single Dataframes, so i implemented a loop, but end up removing extra columns (played with joins but was the best i could get).
The input files (file1...file20) have the following structure:
╔═══╤══════════╤═══════════════════╤═══════════╗
║ │ tag_name │ ts_utc │ tag_value ║
╟───┼──────────┼───────────────────┼───────────╢
║ 0 │ C1 │ Thu Sep 15 2022… │ 1 ║
╟───┼──────────┼───────────────────┼───────────╢
║ 1 │ C1 │ Sat Sep 17 2022… │ 10 ║
╟───┼──────────┼───────────────────┼───────────╢
║ 2 │ C1 │ Sat Sep 17 2022… │ 11 ║
╚═══╧══════════╧═══════════════════╧═══════════╝
...
╔═══╤══════════╤═══════════════════╤═══════════╗
║ │ tag_name │ ts_utc │ tag_value ║
╟───┼──────────┼───────────────────┼───────────╢
║ 0 │ C3 │ Thu Sep 15 2022… │ 3 ║
╟───┼──────────┼───────────────────┼───────────╢
║ 1 │ C3 │ Sat Sep 17 2022… │ 30 ║
╟───┼──────────┼───────────────────┼───────────╢
║ 2 │ C3 │ Sat Sep 17 2022… │ 31 ║
╚═══╧══════════╧═══════════════════╧═══════════╝
And the desired result is:
tag_value header becomes the tag_name (C1,C2...)
Components are merged by date (ts_utc)
tag_name is replaced by constant "sourcetag"
╔═══╤═══════════════════╤═══════════╤═════╤════╤════╗
║ │ ts_utc │ tag_name │ C1 │ C2 │ C3 ║
╟───┼───────────────────┼───────────┼─────┼────┼────╢
║ 0 │ Thu Sep 15 2022… │ sourceTag │ 1 │ 2 │ 3 ║
╟───┼───────────────────┼───────────┼─────┼────┼────╢
║ 1 │ Sat Sep 17 2022… │ sourceTag │ 10 │ 20 │ 30 ║
╟───┼───────────────────┼───────────┼─────┼────┼────╢
║ 2 │ Sat Sep 17 2022… │ sourceTag │ 11 │ 21 │ 31 ║
╚═══╧═══════════════════╧═══════════╧═════╧════╧════╝
Sample code:
https://codepen.io/dotmindlabs/pen/xxJwMqZ?editors=1111
Thanks, any feedback is very appreciatted.

PostgreSql : Merge two rows and add the difference to new column

We have an app which displays a table like this :
this is what it looks like in database :
┌──────────┬──────────────┬─────────────┬────────────┬──────────┬──────────────────┐
│ BatchId │ ProductCode │ StageValue │ StageUnit │ StageId │ StageLineNumber │
├──────────┼──────────────┼─────────────┼────────────┼──────────┼──────────────────┤
│ 0B001 │ 150701 │ LEDI2B4015 │ │ 37222 │ 1 │
│ 0B001 │ 150701 │ 16.21 │ KG │ 37222 │ 1 │
│ 0B001 │ 150701 │ 73.5 │ │ 37222 │ 2 │
│ 0B001 │ 150701 │ LEDI2B6002 │ KG │ 37222 │ 2 │
└──────────┴──────────────┴─────────────┴────────────┴──────────┴──────────────────┘
I would like to query the database so that the output looks like this :
┌──────────┬──────────────┬────────────────────┬─────────────┬────────────┬──────────┬──────────────────┐
│ BatchId │ ProductCode │ LoadedProductCode │ StageValue │ StageUnit │ StageId │ StageLineNumber │
├──────────┼──────────────┼────────────────────┼─────────────┼────────────┼──────────┼──────────────────┤
│ 0B001 │ 150701 │ LEDI2B4015 │ 16.21 │ KG │ 37222 │ 1 │
│ 0B001 │ 150701 │ LEDI2B6002 │ 73.5 │ KG │ 37222 │ 2 │
└──────────┴──────────────┴────────────────────┴─────────────┴────────────┴──────────┴──────────────────┘
Is that even possible ?
My PostgreSQL Server version is 14.X
I have looked for many threads with "merge two columns and add new one" but none of them seem to be what I want.
DB Fiddle link
SQL Fiddle (in case) link
It's possible to get your output, but it's going to be prone to errors. You should seriously rethink your data model, if at all possible. Storing floats as text and trying to parse them is going to lead to many problems.
That said, here's a query that will work, at least for your sample data:
SELECT batchid,
productcode,
max(stagevalue) FILTER (WHERE stagevalue ~ '^[a-zA-Z].*') as loadedproductcode,
max(stagevalue::float) FILTER (WHERE stagevalue !~ '^[a-zA-Z].*') as stagevalue,
max(stageunit),
stageid,
stagelinenumber
FROM datas
GROUP BY batchid, productcode, stageid, stagelinenumber;
Note that max is just used because you need an aggregate function to combine with the filter. You could replace it with min and get the same result, at least for these data.

Filter by all parts of a LTREE-Field

Let's say I have a Table people with the following columns:
name/string, mothers_hierachy/ltree
"josef", "maria.jenny.lisa"
How do I find all mothers of Josef in the people Table?
I'm searching for such a expression like this one: (That actually works)
SELECT * FROM people where name IN (
SELECT mothers_hierachy from people where name = "josef"
)
You can cast the names to ltree and then use index() to see if they are contained:
# select * from people;
┌───────┬───────────────────────┐
│ name │ mothers_hierarchy │
├───────┼───────────────────────┤
│ josef │ maria.jenny.lisa │
│ maria │ maria │
│ jenny │ maria.jenny │
│ lisa │ maria.jenny.lisa │
│ kate │ maria.jenny.lisa.kate │
└───────┴───────────────────────┘
(5 rows)
# select *
from people j
join people m
on index(j.mothers_hierarchy, m.name::ltree) >= 0
where j.name = 'josef';
┌───────┬───────────────────┬───────┬───────────────────┐
│ name │ mothers_hierarchy │ name │ mothers_hierarchy │
├───────┼───────────────────┼───────┼───────────────────┤
│ josef │ maria.jenny.lisa │ maria │ maria │
│ josef │ maria.jenny.lisa │ jenny │ maria.jenny │
│ josef │ maria.jenny.lisa │ lisa │ maria.jenny.lisa │
└───────┴───────────────────┴───────┴───────────────────┘
(3 rows)

Apache Druid : Issue while updating the data in Datasource

I am currently using the druid-Incubating-0.16.0 version. As mentioned in https://druid.apache.org/docs/latest/tutorials/tutorial-update-data.html tutorial link, we can use combining firehose to update and merge the data for a data source.
Step: 1
I am using the same sample data with the initial structure as
┌──────────────────────────┬──────────┬───────┬────────┐
│ __time │ animal │ count │ number │
├──────────────────────────┼──────────┼───────┼────────┤
│ 2018-01-01T01:01:00.000Z │ tiger │ 1 │ 100 │
│ 2018-01-01T03:01:00.000Z │ aardvark │ 1 │ 42 │
│ 2018-01-01T03:01:00.000Z │ giraffe │ 1 │ 14124 │
└──────────────────────────┴──────────┴───────┴────────┘
Step 2:
I updated the data for tiger with {"timestamp":"2018-01-01T01:01:35Z","animal":"tiger", "number":30} with appendToExisting = false and rollUp = true and found the result
┌──────────────────────────┬──────────┬───────┬────────┐
│ __time │ animal │ count │ number │
├──────────────────────────┼──────────┼───────┼────────┤
│ 2018-01-01T01:01:00.000Z │ tiger │ 2 │ 130 │
│ 2018-01-01T03:01:00.000Z │ aardvark │ 1 │ 42 │
│ 2018-01-01T03:01:00.000Z │ giraffe │ 1 │ 14124 │
└──────────────────────────┴──────────┴───────┴────────┘
Step 3:
Now i am updating giraffe with {"timestamp":"2018-01-01T03:01:35Z","animal":"giraffe", "number":30} with appendToExisting = false and rollUp = true and getting the following result
┌──────────────────────────┬──────────┬───────┬────────┐
│ __time │ animal │ count │ number │
├──────────────────────────┼──────────┼───────┼────────┤
│ 2018-01-01T01:01:00.000Z │ tiger │ 1 │ 130 │
│ 2018-01-01T03:01:00.000Z │ aardvark │ 1 │ 42 │
│ 2018-01-01T03:01:00.000Z │ giraffe │ 2 │ 14154 │
└──────────────────────────┴──────────┴───────┴────────┘
My doubt is, In step 3 the count of the tiger is getting decreased by 1 but I think it should not be changed since there are no changes in step 3 for tiger and there is no number change also
FYI, count and number are metricSpec and they are count and longSum respectively.
Please clarify.
when using ingestSegment firehose with initial data like
┌──────────────────────────┬──────────┬───────┬────────┐
│ __time │ animal │ count │ number │
├──────────────────────────┼──────────┼───────┼────────┤
│ 2018-01-01T00:00:00.000Z │ aardvark │ 1 │ 9999 │
│ 2018-01-01T00:00:00.000Z │ bear │ 1 │ 111 │
│ 2018-01-01T00:00:00.000Z │ lion │ 2 │ 200 │
└──────────────────────────┴──────────┴───────┴────────┘
while adding a new data {"timestamp":"2018-01-01T03:01:35Z","animal":"giraffe", "number":30} with appendToExisting = true, i am getting
┌──────────────────────────┬──────────┬───────┬────────┐
│ __time │ animal │ count │ number │
├──────────────────────────┼──────────┼───────┼────────┤
│ 2018-01-01T00:00:00.000Z │ aardvark │ 1 │ 9999 │
│ 2018-01-01T00:00:00.000Z │ bear │ 1 │ 111 │
│ 2018-01-01T00:00:00.000Z │ lion │ 2 │ 200 │
│ 2018-01-01T00:00:00.000Z │ aardvark │ 1 │ 9999 │
│ 2018-01-01T00:00:00.000Z │ bear │ 1 │ 111 │
│ 2018-01-01T00:00:00.000Z │ giraffe │ 1 │ 30 │
│ 2018-01-01T00:00:00.000Z │ lion │ 1 │ 200 │
└──────────────────────────┴──────────┴───────┴────────┘
is it correct and expected output? why the rollup didn't happen?
Druid has actually only 2 modes. Overwrite or append.
With the appendToExisting=true, your data will be appended to the existing data, which will cause that the "number" field will increase (and the count also).
With appendToExisting=false all your data in the segment is overwritten. I think this is what happening.
This is different then with "normal" databases, where you can update specific rows.
In druid you can update only certain rows, but this is done by re-indexing your data. It is not a very easy process.
This re-indexing is done by an ingestSegment Firehose, which reads your data from a segment, and then writes it also to a segment (can be the same). During this process, you can add a transform filter, which does a specific action, like update certain field values.
We have build a PHP library to make these processes more easy to work with. See this example how to re-index a segment and apply a transformation during the re-indexing.
https://github.com/level23/druid-client#reindex

Pentaho - How to show complete date in line chart's X axis

I'm creating a Pentaho CDE dashboard and I'm having some difficulties in setup how the date is shown in a line chart. The below chart is what I have at this time:
As you can see, the X axis has numbers from 1-6, they are months. What I want do is show more information in this axis instead of simply 1, I want show "January / 2013" for example, but I have no idea of how can I achieve this.
My Mondrian schema for date dimension is this:
<Dimension type="TimeDimension" visible="true" foreignKey="data_id" highCardinality="false" name="Data">
<Hierarchy name="data" visible="true" hasAll="true">
<Table name="dimensao_data">
</Table>
<Level name="ano" visible="true" column="ano" type="Numeric" uniqueMembers="true" levelType="TimeYears" hideMemberIf="Never">
</Level>
<Level name="semestre" visible="true" column="semestre" type="Numeric" uniqueMembers="false" levelType="TimeHalfYears" hideMemberIf="Never" captionColumn="labelSemestre">
</Level>
<Level name="quarto" visible="true" column="quarto" type="Numeric" uniqueMembers="false" levelType="TimeQuarters" hideMemberIf="Never" captionColumn="labelQuarto">
</Level>
<Level name="mes" visible="true" column="mes" type="Numeric" uniqueMembers="false" levelType="TimeMonths" hideMemberIf="Never" captionColumn="labelMes">
</Level>
<Level name="dia" visible="true" column="dia" type="Numeric" uniqueMembers="false" levelType="TimeDays" hideMemberIf="Never">
</Level>
</Hierarchy>
</Dimension>
and this is the MDX I'm using to retrieve data for the chart:
SELECT NON EMPTY {[Measures].[valor]} ON COLUMNS,
NON EMPTY CrossJoin({[pagamento.forma].[moeda].MEMBERS}, {[Data.data].[mes].MEMBERS}) ON ROWS
FROM [Vendas]
WHERE {[Empresa.empresa].[MATRIZ]}
NEW INFORMATION
When I use debug mode I can see that Data.data don't comes only with month value and in String format:
[pvc.LineChart ]: DATA SOURCE SUMMARY
╔═════════╤═════════════════════╤═════════════╤══════════╗
║ Name │ pagamento.forma │ Data.data │ valor ║
╟─────────┼─────────────────────┼─────────────┼──────────╢
║ Label │ │ │ ║
╟─────────┼─────────────────────┼─────────────┼──────────╢
║ Type │ String │ String │ Numeric ║
╟─────────┼─────────────────────┼─────────────┼──────────╢
║ 1 │ "BOLETO BANCARIO" │ "1" │ 10469.15 ║
║ 2 │ "BOLETO BANCARIO" │ "2" │ 16279.45 ║
║ 3 │ "BOLETO BANCARIO" │ "3" │ 16279.45 ║
║ 4 │ "BOLETO BANCARIO" │ "4" │ 5810.3 ║
║ 5 │ "BOLETO BANCARIO" │ "5" │ 16279.45 ║
║ 6 │ "BOLETO BANCARIO" │ "6" │ 5810.3 ║
║ 7 │ "CARTÃO DE CRÉDITO" │ "1" │ 10243.57 ║
║ 8 │ "CARTÃO DE CRÉDITO" │ "2" │ 9178.03 ║
║ 9 │ "CARTÃO DE CRÉDITO" │ "3" │ 10273.08 ║
║ 10 │ "CARTÃO DE CRÉDITO" │ "4" │ 10110.4 ║
║ 11 │ "CARTÃO DE CRÉDITO" │ "5" │ 10366.3 ║
║ 12 │ "CARTÃO DE CRÉDITO" │ "6" │ 10768.75 ║
║ 13 │ "CARTÃO DE DÉBITO" │ "1" │ 15584.84 ║
║ 14 │ "CARTÃO DE DÉBITO" │ "2" │ 12400.53 ║
║ 15 │ "CARTÃO DE DÉBITO" │ "3" │ 13517.65 ║
╟─────────┼─────────────────────┼─────────────┼──────────╢
║ (15/41) │ │ │ ║
╚═════════╧═════════════════════╧═════════════╧══════════╝
So, I believe the problem is with the result of Data.data. How can I purchase the complete date to show in chart?
There are multiple ways to achieve that:
At the query level:
Define a Measure that holds the info you want to display:
With member [Measures].[Date Label] as [data].CurrentMember.Caption || " / " || Ancestor( [data].CurrentMember, [data].[ano]).Name
This should give you "2013 / January" as the output. Just filter out the columns you want to pass to the chart when defining the CDA query.
At the chart level.
You can change what the chart displays by playing around with the PostFetch of the chart. Something like
function(data){
var results = data.resultset.map(function(d){
// Tweak the contents of each line of data here
// You will want to take the value of d[0] and replace it by
// something else.
return d;
});
data.resultset = results;
return data
}
I prefer to have this type of thing done at the query level, it makes the dashboard simpler to understand and maintain. But it depends a lot on the specifics.