#[SOLVED] ApplyLinearImpulse not doing anything

1 messages · Page 1 of 1 (latest)

lusty jewel
hollow timber
#

You aren't writing the physics velocity back to the entity

#

you are just modifying the local struct

lusty jewel
#

@hollow timber can you guide me how to do that? I saw a few tutorials but I dont get it

hollow timber
#

You just need to call SetComponent(entity, pv)

#

struct vs class

#

I always find thinking of this as imagine pv was an int

#

int pv = SystemAPI.GetComponent<int>(hitting);
pv = 3;

#

i'm pretty sure you'd now realize this hasn't actually done anything yet

lusty jewel
#

hold on this just confusing XD give me 2 mins to get this around my head

hollow timber
#

what you're missing is just
SystemAPI.SetComponent(entity, pv)

#

(there's a bunch of other issues with this system though)

lusty jewel
#

IT WORKED!! Thank you so much, the previous tutorials I saw didnt show this part and could I find it in the documentation. Although I would like to understand if I could have a few minutes of your time.

I got reference to the physicsVelocity so shouldn't APplyForce apply straight back to the entities component?

hollow timber
#

EntityQueryBuilder builder = new EntityQueryBuilder(Allocator.Temp).WithAll<PhysicsWorldSingleton>();
EntityQuery singletonQuery = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntityQuery(builder);```
#

you shouldn't be doing this

#

you should use the systems entitymanager

#

EntityManager exists as a property on the system

#

use that instead of
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

#

this should not be create each frame

EntityQueryBuilder builder = new EntityQueryBuilder(Allocator.Temp).WithAll<PhysicsWorldSingleton>();
EntityQuery singletonQuery = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntityQuery(builder);
var physSingleton = singletonQuery.GetSingleton<PhysicsWorldSingleton>();```
the easiest way is just to do
var physSingleton = SystemAPI.GetSingleton<PhysicsWorldSingleton>()
hollow timber
#

        EntityQueryBuilder builder = new EntityQueryBuilder(Allocator.Temp).WithAll<PhysicsWorldSingleton>();
        EntityQuery singletonQuery = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntityQuery(builder);
        var physSingleton = singletonQuery.GetSingleton<PhysicsWorldSingleton>();

        singletonQuery.Dispose();
        builder.Dispose();```
delete all this
#

replace with
var physSingleton = singletonQuery.GetSingleton<PhysicsWorldSingleton>();

lusty jewel
#

but now I have a error on SingletonQuery

lusty jewel
hollow timber
#

yes

#

either use SystemAPI.QueryBuilder which will handle it for you

#

or for singletons just use GetSingleton

lusty jewel
#

sorry im new and this is getting a bit confusion.

I should use singletonQuery instead of making everything everytime. Which I understand but Now that I have commented

    EntityQuery singletonQuery = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntityQuery(builder);

Im getting a error because builder is not a variable anymore

hollow timber
#

you don't n eed a builder

#

delete it

#

        EntityQueryBuilder builder = new EntityQueryBuilder(Allocator.Temp).WithAll<PhysicsWorldSingleton>();
        EntityQuery singletonQuery = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntityQuery(builder);
        var physSingleton = singletonQuery.GetSingleton<PhysicsWorldSingleton>();

        singletonQuery.Dispose();
        builder.Dispose();```

delete everything here
#

replace it with
var physSingleton = SystemAPI.GetSingleton<PhysicsWorldSingleton>();

lusty jewel
#

It worked. Thank you so much