Using PhysicsServer & Multimesh to Optimize 3D Performance - Hundreds of Projectiles in Godot 3.4

  Рет қаралды 6,887

devmar

devmar

Күн бұрын

Пікірлер: 16
@Smaxx
@Smaxx 3 жыл бұрын
Great explanation on physics server. However, since this is all about performance, looping through bullets every iteration (`Array.find()` will have to compare each entry in the array in worst case scenarios) feels like a very bad and unnecessary idea. I'd suggest just counting up, picking bullets by index and only increasing the index if you didn't delete the bullet. This should lead to the very same result anyway but in a fraction of the time (O(n) vs. (O(n²)).
@actualdevmar
@actualdevmar 3 жыл бұрын
Yea I ended up just using a counter even though I can't say there was a difference. But logically it makes sense as I only really need an index to differentiate between the items.
@randompast
@randompast 2 жыл бұрын
Fantastic tutorial!
@alexanderhuliakov6012
@alexanderhuliakov6012 3 жыл бұрын
Really nice explanation and code, but 9:08 looks game breaking
@actualdevmar
@actualdevmar 3 жыл бұрын
there are simple ways to fix that like increasing the min distance to destination which will make the bullet disappear sooner. But you're right, fixing this is likely to introduce other problems. That's why I mentioned the limitations.
@psuw
@psuw 3 жыл бұрын
How did you do the bullet trails 😭
@medieval.software
@medieval.software 3 жыл бұрын
At @4:00 I think the paradigm is called "Factory". You want a BulletFactory. Pew pew :)
@Adam-mb3jp
@Adam-mb3jp 3 жыл бұрын
awesome idea! I'm doing something similar to Neir as far as bullets go, so I adapted this to my needs, using Area physics. The collision precision is important to me so I had to use a work around with a script reference to make sure the collision works and deletes correctly without using the scene tree - maybe this would help someone :) Main bullets script extends Node const SPEED := 10.0 onready var multi_mesh_instance : MultiMeshInstance = $MultiMeshInstance onready var multi_mesh : MultiMesh = multi_mesh_instance.multimesh var array : Array func createShoot(at_position : Vector3, basis : Basis): var bullet : RID = PhysicsServer.area_create() var xform := Transform() xform.origin = at_position xform.basis = basis var shape = PhysicsServer.shape_create(PhysicsServer.SHAPE_SPHERE) PhysicsServer.shape_set_data(shape,1.5) var array_data : Dictionary = {"rid":bullet,"xform":xform} var script = load("res://data/enemies/BulletScript.gd").new(self,array_data) array_data.script = script PhysicsServer.area_set_monitor_callback(bullet,script,"remove") PhysicsServer.area_set_collision_layer(bullet,0b1000) # specific to my needs PhysicsServer.area_set_collision_mask(bullet,0b110010) # specific to my needs PhysicsServer.area_set_transform(bullet,xform) PhysicsServer.area_add_shape(bullet,shape) PhysicsServer.area_set_space(bullet,multi_mesh_instance.get_world().space) array.append(array_data) func _physics_process(delta: float) -> void: multi_mesh.instance_count = array.size() var idx : int = 0 for i in array: i.xform.origin = i.xform.origin-(i.xform.basis.z*delta*SPEED) PhysicsServer.area_set_transform(i.rid,i.xform) multi_mesh.set_instance_transform(idx,i.xform) idx += 1 func removeByDictionary(dic : Dictionary): PhysicsServer.free_rid(dic.rid) array.erase(dic) Workaround BulletScript.gd for collision: extends Reference var dic : Dictionary var bullets_manager func _init(p_bullets_manager, p_dic : Dictionary) -> void: dic = p_dic dic.script = self bullets_manager = p_bullets_manager func remove(exited_body : bool,collider_rid : RID, collider_instance : int, collider_shape : int, area_shape : int): bullets_manager.removeByDictionary(dic)
@actualdevmar
@actualdevmar 3 жыл бұрын
Thanks for sharing your implementation. I think this method with 2 corresponding arrays (object transforms and multimesh instances) could be used for lots of other things as well, even as an alternative for particles where more control is required.
@deloreanmail103
@deloreanmail103 3 жыл бұрын
What program are you using to draw? Leonardo?
@actualdevmar
@actualdevmar 3 жыл бұрын
Nah photoshop
@tomtomkowski7653
@tomtomkowski7653 2 жыл бұрын
What about the pooling method? Spawn 1000 bullets at a start and show them at the position instead of instantiating each time? And a bullet can be just a sprite stretched from the barrel to the target you get by a raycast the moment you shoot. Moving bullet is then just a moving texture's UV. All would be pre-instantiated and you would have only one raycast per shot. Just have to find out how to calculate part of texture with a bullet UV coordinates to the world coordinates to check for a collision if the player will run into the already fired bullet. Probably stupid ideas by hey... xD
@KaletheQuick
@KaletheQuick 3 жыл бұрын
Why are raycasts inaccurate? I've had luck with them but is something different about them in Godot?
@actualdevmar
@actualdevmar 3 жыл бұрын
They are accurate but in this situation they're insufficient. A raycast will scan for intersections between 2 points only. With so many scans it's likely that an intersection goes undetected. Collision shapes scan for collisions across multiple points that make up the collision shape so they're much more likely to detect collisions. At the cost of performance, of course. So it all depends on one's game design.
@BTL_Nari
@BTL_Nari 3 жыл бұрын
Make it a 3rd person shooter again
@unity3d313
@unity3d313 3 жыл бұрын
it's cool ilike this game
Optimization Tutorial: OCCLUSION CULLING in Godot
8:29
Optimizing my Game so it Runs on a Potato
19:02
Blargis
Рет қаралды 688 М.
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН
小丑教训坏蛋 #小丑 #天使 #shorts
00:49
好人小丑
Рет қаралды 54 МЛН
5 Awesome Godot Addons That You Should Give a Try
12:23
LucyLavend
Рет қаралды 59 М.
We mined BITCOIN in Minecraft!
27:50
Armadillo28
Рет қаралды 228 М.
We made Vampire Survivors BUT in 10 Lines of Code
7:08
PlayWithFurcifer
Рет қаралды 1 МЛН
Giving Personality to Procedural Animations using Math
15:30
t3ssel8r
Рет қаралды 2,6 МЛН
I Made My First Game in Godot in 3 Weeks...
26:21
Jack Sather
Рет қаралды 464 М.
Trying to Optimize my 3D Game in Godot 3.4
4:23
devmar
Рет қаралды 42 М.
Answering Your Questions
29:12
Sebastian Lague
Рет қаралды 327 М.
7 Optimization Tips to 10X your Game Performance
5:23
Venex Source
Рет қаралды 22 М.
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН