#[SOLVED] ApplyLinearImpulse not doing anything
1 messages · Page 1 of 1 (latest)
You aren't writing the physics velocity back to the entity
you are just modifying the local struct
@hollow timber can you guide me how to do that? I saw a few tutorials but I dont get it
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
hold on this just confusing XD give me 2 mins to get this around my head
what you're missing is just
SystemAPI.SetComponent(entity, pv)
(there's a bunch of other issues with this system though)
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?
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>()
at the end?
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>();
but now I have a error on SingletonQuery
OH I GET IT! I should not be creating these variables every frame. Instead I can do it only once?
yes
either use SystemAPI.QueryBuilder which will handle it for you
or for singletons just use GetSingleton
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
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>();
It worked. Thank you so much