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²)).
@actualdevmar3 жыл бұрын
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.
@randompast2 жыл бұрын
Fantastic tutorial!
@alexanderhuliakov60123 жыл бұрын
Really nice explanation and code, but 9:08 looks game breaking
@actualdevmar3 жыл бұрын
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.
@psuw3 жыл бұрын
How did you do the bullet trails 😭
@medieval.software3 жыл бұрын
At @4:00 I think the paradigm is called "Factory". You want a BulletFactory. Pew pew :)
@Adam-mb3jp3 жыл бұрын
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)
@actualdevmar3 жыл бұрын
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.
@deloreanmail1033 жыл бұрын
What program are you using to draw? Leonardo?
@actualdevmar3 жыл бұрын
Nah photoshop
@tomtomkowski76532 жыл бұрын
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
@KaletheQuick3 жыл бұрын
Why are raycasts inaccurate? I've had luck with them but is something different about them in Godot?
@actualdevmar3 жыл бұрын
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.