How to make a pokeball effect in godot?

Ok after a long time struggling to make this works, i think i did it haha, thank you @gertkeno and @nutlike4693 .

So i’ll put my solution here to who wants to make something similar to what i did:

  1. I followed the suggestion and add a Area3D, the Area3D gives you an option to make gravity be replaced and it behaves like a magnet, it would fits well to me except the part that every CatchParticle was attracted by the first area it found.

  2. So to solve that, i add an id for each CatchParticle randomly and also add a script to Area3D to applies the force just in the specific CatchParticle that is created and area that’s interacting with, to make sure that every CatchParticle will be attracted to its correspondent card:

CardPhysicItem:
image

play_catch_particle script:

func play_catch_particle()->void: #This function basically instantiate the ray(gpupartcle3D) that will be appears in the enemy position and will go to the card position in air
	var instance:Object = preload("res://scenes/magic/catch_particle.tscn")
	var instance_energy:CatchParticle = instance.instantiate() #Instantiate the catch_particle in the enemy position
	instance_energy.position = enemy_ref.global_position + Vector3(0, 1, 0) #Add one height unit to ensure the catch particle appears above the ground
	instance_energy.transform.basis = enemy_ref.global_transform.basis
	randomize()
	id_particle = randi() % 100 #id_particle will be a global variable of card_physics_item class
	print("randomize: ", id_particle)
	instance_energy.id = id_particle #set the id to catchparticle
	get_parent().add_child(instance_energy)

Magnet Script:

func _on_magnet_body_entered(body: Node3D) -> void: #Signal to check if a body entered  in the maget area
	if body is CatchParticle: #Test if body is catchparticle
		if body.id == id_particle: #Check id
			# Calculate the direction of body attraction
			var direction = global_transform.origin - body.global_transform.origin
			direction = direction.normalized()
			# Apply the force without the gravity influence
			body.gravity_scale = 0
			body.apply_central_impulse(direction * 1)  
	pass 

It works flawsly well in this scneario:

But it’s still buggy in my game, probably due to the inertia. Maybe adjusting the throw card force would solve this issue:

2 Likes