Interacting two different objects in Threejs

Hello!

Me and a friend want to create a small game in Threejs. This game is an office where there will be some characters that work on it. The characters and the office will be differents GLTF files. And we wondering how we will make the characters interact with the cenario from the office.

Example:

“A character approches to a table and pulls the chair to sit on it.”

What is the best way to approch a situation like this? Like using AnimationMixer or some engine…

I am open to all kind of tips!!

Thanks :smiley:

Imo unless either of you is very experienced with 3D physics & interactions, animations and limiting your expectations (ie. scripted interactions) may be your best way to go.

Or maybe you know an example of a game / app that does what you want to do - then it may be easier to tell you how they did it.

1 Like

I think a good example is this game when the person pulls the cars door:

  1. Damn that Sketchbook looks nice and that code so clean I’ll read it for bedtime.
  2. What I see from the code there are 2 parts (separated between different vehicles):
  • When F is pressed you position and rotate character properly next to the vehicle door (this is done by code, calculating differences between car and character directions and the entry point)
  • When character is aligned with left or right door, you play entry animation depending on the side on which the character is (depending on the side of the door character then becomes either a driver or a passenger.)

So all in all it is complex (looking just at the amount of code.), but if you have pre-scripted actions, like opening doors, seating down on a chair etc. it can be simplified a bit. First, you’ll still need animations, on both character and interaction objects. Second, for each object (either in model or some data structure) define an “entry point”.
Then in code - first ensure character is aligned with the entry point (if you don’t feel like doing all these calculations, just set character position and rotation to the entry point like minecraft does), then play the animation.

2 Likes

:smiley:

Thanks for your answer and time spent!

I was hopping i could turn around a little bit this kind of interaction with some framework or something similar. At least i know where to start from. Thank you again!

(pikachu is the best)