Closed windkomo closed 4 years ago
I set up a codesandbox showing my issue : https://codesandbox.io/s/agitated-vaughan-n5zid The sphere should steer towards the box.
this is very similar to https://github.com/react-spring/use-cannon
there are a few mistakes you made.
you set position on the mesh, but it has to be set in the entity, otherwise the gamemanager doesn't know it. for the manager the vehicle was already at 0/0/0 that's why nothing moved
you forgot to set matrixAutoUpdate. you need that if you set the matrix yourself. otherwise change the code in setRenderComponent and set position/rotate/scale directly
with react you have the chance to clean up the imperative mess. try to see the concerns: you have a player, a vehicle and a manager. the manager is the parent to the entities, so it should control the logic.
here's a working draft: https://codesandbox.io/s/interesting-tree-f0rqo
ps, i didn't know yuka, but if you do something cool with it, let me know - would love to retweet so others can learn from this.
That makes sense, thanks for taking time to explain this!
Hi, I'm trying to use yuka (https://github.com/Mugen87/yuka) to implement some kind of basic game AI and I'm having trouble figuring out where to put the imperative code. I want to implement this example: demo: https://mugen87.github.io/yuka/examples/steering/seek/ code: https://github.com/Mugen87/yuka/blob/master/examples/steering/seek/index.html
What I want to do it make a vehicle steer towards a target, Basically, the imperative code looks like this:
So what I am doing is storing a reference to the target mesh in a global store, and use a React ref to a group as a vehicle. I am using seMemo hook to store class instances like entityManager and vehicle inside a component, and set stuff like seekBehavior inside a useEffect hook. In a useFrame hook, I am updating the entityManager with the time delta. Anything I am missing here?