veeti512 / wadblender

13 stars 3 forks source link

Discussion on Lara collision in Unity #10

Open TokyoSU opened 3 years ago

TokyoSU commented 3 years ago

Dont know if it's your tool or unity so i will post here to see if you have a solution for this :) an example: https://i.imgur.com/wpiFkRD.png I dont want to edit each animation frame by frame to match the mesh :'( PS: this problem is impacting the shadow in unity (like shadow disappearing if the mesh is not see).

veeti512 commented 3 years ago

you need to update the Lara bounding box programmatically. Blender can't do that, you need to add a curve to the animation and update your collider accordingly in real time. You can get the bounding box coordinates values using the export json in wad blender.

TokyoSU commented 3 years ago

you know lara have 500~ anim and more than 20000+ frame right xD

TokyoSU commented 3 years ago

and i need to do that for all entity too O.O'

EDIT: the json export throw me this error:

Python: Traceback (most recent call last):
  File "C:\Users\TokyoSU\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\wadblender\import_wad.py", line 339, in execute
    lara.main(context, materials, wad, options)
  File "C:\Users\TokyoSU\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\wadblender\lara.py", line 267, in main
    save_animations_data(animations[anim], anim, options)
TypeError: save_animations_data() missing 1 required positional argument: 'options'

location: <unknown location>:-1
veeti512 commented 3 years ago

Argh, I'll check tomorrow. The previous commit I think worked. Anyway, that's easy in c sharp, I can give you some code but it is for tr4 and you need to adapt it for tr3.

TokyoSU commented 3 years ago

Do the code is "hardcoded" for TR4 mesh ? A script to do it auto would be great, like loading the json and changing each anim and frame to match the bounding box would be possible ? I think it would be to manually select the anim and the anim in the json to do that. but the frame in unity are normalized so it will be difficult

veeti512 commented 3 years ago

Tomorrow I'll check to be sure, the only change should be the number of meshes in Lara's model. The script imports the Json and builds a unity controller taking into account of animation commands, animation bounding boxes (I think they are just hit boxes for enemies shooting at Lara, rolling balls, etc) state changes, dispatches and sound. For normalized time you need just to divide by the number of frames.

Anyway, after this you should use this data to control Lara. I have some code also for that but it's very alpha and got burned out on that project.

TokyoSU commented 3 years ago

If we need the json to export, then the options error is a big problem for unity user, can it be fixed first ?

veeti512 commented 3 years ago

It should be fixed, now I search for the c# code. It is a bit problematic since my laptop overheats and unity is heavy! Hope it does not shut down.

veeti512 commented 3 years ago

Check if you can run this unity project:

https://mega.nz/file/pFAVBIZT#zQbweGq1nAUS3FqHjy9qqcCSS84ilghtNTDzmR6huI4

the import code is TRLE\Assets\Scripts\Lara\GenerateLaraAnimations.cs but needs some dependencies so I uploaded everything. See if you can make use of the code. I was trying to make a TRLE as in TR4 but without the floor limitations. Something like AOD but with Lara tr4 game mechanics/animations. The problem is that it was not fun and also I have not the patience to design levels. So I lost interest.

TokyoSU commented 3 years ago

Thank :) i will check it. For the level design, you can use TombEditor and export each Room, then change some think in the room, then import it to unity, it's what i do, and it work fine, i just need to found the correct size :x EDIT: Fixed for the export json :)

TokyoSU commented 3 years ago

Your lara is almost perfect :) there are some thing like Collision that go a bit upward and is hard to look for the eyes and the foot IK that are a bit well not setup perfectly, i will work with the lara script you created, it save lot of time 👍 and i will improve it a bit. Do you think the grab will work with a Convex Hull Collision or Mesh Collision because it will save a lot of time too, since i can just get a mesh collision for the room exported with TombEditor ? or do i need to have the ProBuilder ? EDIT: I dont know about ProBuilder before but it look like what i need to for replacing the need of TombEditor, for now i will do with TombEditor way.

TokyoSU commented 3 years ago

The script also fix #4 with the double LARA_RIG in the name of animation in the fbx file (only for unity) :)

veeti512 commented 3 years ago

Yes, camera and foot ik are pretty basic. IK is a big problem because she walks with straight legs like a penguin. When she needs to rise a step at walking speed, the result is glitchy. I think that animation should be rethought.

For the collisions, I was exploring different possibilities, so you will find a lot of red balls spitting rays everywhere :D depending on what you want to do you should rethink them entirely. If you make the floor as Core Design did, you can check what block is underneath, in front, etc and act accordingly. I wanted to have more freedom and things got trickier. For grabbing I put two balls in front of Lara: if the upper collide with nothing and the lower collides, Lara can grab, goes into hang state and gravity turns off. In order to see if she can shimmy over left/right I sent a ray from her left hand downwards to see if there is something with a reasonable slope. So, if the surface is curvy I think she would not move. There are also a lot of other details to take care of.

Regarding ProBuilder, Lara should collide with everything, you don't need it. Anyway, the code you see it's just me playing. making changes will probably make you waste more time than redesign collisions from scratch. Instead, the mechanism for animation changes is pretty faithful. I was following the leaked tr3 beta source code.

TokyoSU commented 3 years ago

i could see the leaked source code when is was seing lara_as_xx function name xD where is lara_col_xx function :D

TokyoSU commented 3 years ago

Actually it's not the collision box but the visibility box that are messed up, like in the image, and i think this box is inversed, if you check lara head when she is animated, you can see a white box moving and inversed. the problem is this box is used for clipping the mesh, if the box disappear from the camera, then unity will remove the mesh to optimize the drawing. but since this box is not correctly positioned, you can see something the hand be removed but the mesh was actually on the camera, but not the box ! Also this box is defined for each frame of a animation, so changing manually will be well... Well the script add a dynamic box collision and this is a precious time saving :)

veeti512 commented 3 years ago

I'm not sure if I understood correctly because I didn't specified any box for visibility purposes. Just to avoid confusion here are the main TRLE collision behaviors in tomb raider 12345:

(1) The collision box with respect to TRLE blocks is hard-coded (both in TRLE and my Unity playground). It is wrong in my Unity code probably because I was testing with another outfit and forgot to tune it back (I think I was using Lara TR3 FMV in models folder, not sure though). This box is mostly of fixed dimension and follows Lara root mesh. It changes for instance when she crouches so that she can pass through tunnels (I did not implement this in Unity, but that is what TR3/5main source code does). In order to alter this you can act on the character controller panel modifying the center and height values.

(2) The collision box with respect to WAD statics is a box specified in the WAD file. There is also a visibility box but I guess it is not used.

(3) The collision with respect to WAD movables is a fixed sphere with center and radius specified in the WAD file. There is also a bounding box for each animation frame but I didn't investigate on what it does. I just drew it in Unity but it is not used.