Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calling method from _integrate_forces() doesn't always register #43806

Closed
tommiemartin opened this issue Nov 23, 2020 · 7 comments
Closed

calling method from _integrate_forces() doesn't always register #43806

tommiemartin opened this issue Nov 23, 2020 · 7 comments

Comments

@tommiemartin
Copy link

Godot version:
3.2.3

OS/device including version:
OSX, iOS, Android

Not sure if this is related to the other physics issue but calling methods or signals with in integrate_forces contacts isn't always registering.

This code works majority of the time but for some reason sometimes fails to trigger the objects method.

func _integrate_forces(s): 
	velocity = s.get_linear_velocity()
	spin = s.get_angular_velocity()
	step = s.get_step() 
 
		for x in range(s.get_contact_count() ): 
		  var cn = s.get_contact_local_normal(x) 
		  var p = s.get_contact_collider_position(x) 
	  	  var o = s.get_contact_collider_object(x)
 
		  # Push collisions,  
		  if o is KinematicBody:
			if o.has_method("_push"):
				o._push(-cn * step)
#				o.call_deferred("_push",-cn * step) # recommend on discord doesn't help
 
		  #Play sound 
		  if abs(cn.z) >= 0.6:
			  apply_central_impulse(-velocity * step)
			  if o.get_collision_layer_bit(9):
				soundWall.play() # playSoundWallHit()
@Calinou
Copy link
Member

Calinou commented Nov 23, 2020

Can you try putting print statements in various branches of the code to see which branch isn't being called when it should?

@tommiemartin
Copy link
Author

Yes, it appears to be in the s.get_contact_count() loop. (contact count set to 3 to account for the floor / possible wall, and can sleep disabled. I tried it with this print and sometimes it registering and sometimes I'll be colliding /pushing against the enemy with nothing triggering.

		if not o is StaticBody:
			print("Player collided with ", o.get_name() )

@pouleyKetchoupp
Copy link
Contributor

@tommiemartin Please upload a minimal project to allow contributors to test this issue with your scene setup.

@tommiemartin
Copy link
Author

Honestly I'm not using Godot anymore and ended up shipping my game with this issue, Be it a problem with physics or problem between chair and screen. I'm not sure if _integrate_forces(s): really gets used that much the way I was doing it. If it helps I can just close this out.

@pouleyKetchoupp
Copy link
Contributor

Thanks for your answer! Yes, let's close it for now since we don't have a specific repro case.

For anyone hitting a similar issue, please comment with a minimal project so it can be investigated.

@valknor
Copy link

valknor commented Feb 21, 2022

Hello,

I have experienced a similar problem (using Godot_v3.4.2-stable_x11.64 for Linux), which appears to be restricted to the Bullet Physics Engine. My code is below:

_integrate_forces(state):

	print(state.get_contact_count())
	if(state.get_contact_count() >= 1):  #this check is needed or it will throw errors 
		local_normal0 = state.get_contact_local_normal(0)

Neither state.get_contact_count, nor state.get_contact_local_normal consistently returns a value other than 0, even when the rigid body is clearly on the ground. I've found that this issue depends on the kind of collision mesh in use, with trimesh collision siblings producing this problem far less often. However on more complex meshes, such as inside cylinders this still sometimes happens. I would like to say using Godot Physics is a workaround, but it introduces other issues with friction and some unusual collision problems.

I am uploading a minimal version of my project which should reproduce these problems for you. Rolling toward the middle (green ramp) consistently returns 0 for the above printout. Controls are pretty standard, WASD, Space for jump, and mouse for camera rotation.

gammaball.zip

@Calinou
Copy link
Member

Calinou commented Feb 21, 2022

@valknor Please open a new issue with the minimal reproduction project attached.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants