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

add infinte inertia property to characterbody3D in godot4 #4805

Closed
djmaesen opened this issue Jul 4, 2022 · 4 comments
Closed

add infinte inertia property to characterbody3D in godot4 #4805

djmaesen opened this issue Jul 4, 2022 · 4 comments

Comments

@djmaesen
Copy link

djmaesen commented Jul 4, 2022

Describe the project you are working on

fps

Describe the problem or limitation you are having in your project

in godot 3 there was an infinite inertia property for characterbodies so they would automaticly interact with rigidbodies.
in godot4 this was removed. now a characterbody3D doesnt automaticly interact with rigidbodies.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

add an option to enable infinite inertia to characterbody3D.
doesnt need to be standard, just an option

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

eg a ui button to enable it or a line of code in move_and_slide(infinite inertia , bool , true)

If this enhancement will not be used often, can it be worked around with a few lines of script?

dont know

Is there a reason why this should be core and not an add-on in the asset library?

this will make it easier for my character setup

@Calinou
Copy link
Member

Calinou commented Jul 4, 2022

Infinite inertia was removed by design. You don't need it anymore after configuring collision layers accordingly: godotengine/godot#31981 (comment)

@djmaesen
Copy link
Author

djmaesen commented Jul 4, 2022

reading the comments i got it working , tnx!

@Calinou Calinou closed this as not planned Won't fix, can't repro, duplicate, stale Jul 4, 2022
@hellotherekyle
Copy link

Infinite inertia was removed by design. You don't need it anymore after configuring collision layers accordingly: godotengine/godot#31981 (comment)

I can't figure out how to get it working correctly... For instance if I push a box into a wall it teleports and warps all over the place? Is there a way to avoid this without infinite inertia?

@Kinaite
Copy link

Kinaite commented Sep 28, 2023

Hey @hellotherekyle

You can do as the comment said (Or this video) to have unidirectional collision, meaning that, if you want to push a node, but this node does not collide with the player. This can cause some weird behavior depending on what you are doing (like clipping over walls if you keep pushing the nodes against it).

Now if you want you player to move for example a box, and when the box hits a wall, the box does not move anymore (nor the player) you need to do it by code.
This QA teaches you how to do it:
https://ask.godotengine.org/147759/how-to-push-a-rigidbody2d-with-a-characterbody2d

This can also be translated to 3d by just replacing the Rigidbody2d with a Rigidbody3D, here is a sample code that does exactly that:

extends CharacterBody3D
@export var pushForce = 500
var move_direction = Vector3()

func _process(delta):
	move_direction = Vector3()
	if Input.is_action_pressed("move_left"):
		move_direction -= transform.basis.x
	if Input.is_action_pressed("move_right"):
		move_direction += transform.basis.x
	if Input.is_action_pressed("move_forward"):
		move_direction -= transform.basis.z
	if Input.is_action_pressed("move_backwards"):
		move_direction += transform.basis.z

func _physics_process(delta):
	velocity = move_direction * 15
	if move_and_slide():
		for i in get_slide_collision_count():
			var col = get_slide_collision(i)
			if col.get_collider() is RigidBody3D:
				print(col.get_collider())
				col.get_collider().apply_force(col.get_normal() * -pushForce)

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