Love the ending bc is true I tried to do a 3D breakout bc it was "simple" and I almost end up, calculating all normals and velocities by hand xD, at the end I conformed myself with a decent result and left it as a nice prototipe of a simple game that I will polish if necessary, but physics took me by surprise when they are part of the gameplay
Doing a 3d breakout now. Personally, I would recommend a characterbody for the ball and paddles just due to this. I'm using rigidbody's for the bricks. I want some of the bricks to slide. I can get them to move, but it doesn't feel right, so digging into that some.
I can finally implement physics in my game with character bodies. It was a big problem for me, cause I am not a coder, but i wanted it so bad! Learning something new everyday. Definitely like and subscribe.
You can get some funny results while playing around with the BOUNCE property on the RigidBody3D. Managed to launch myself into space again after colliding with two objects which had bounce set to 1. I saw Azathoth this time. Wouldn't recommend.
I've just used a rigid body for my character. I realize that I have made it harder on myself in some ways, but I can work around those issues and as a bonus I don't have to worry about making it possible for the character to be moved by a moving obstacle in physically accurate manner (i. e. character flies away after being hit by an oversized hammer) and weird collision issues such as character being stuck in the walls or whatever as the physics engine will do that work for me.
Yes this is definitely one possible solution, this could be good for a lot of games. I probably should have mentioned this in the video too. Like you said it could have some downsides but all depends on what type of game you're making.
It doesn't appear to be working. I don't have the weight shapes you have in the video. But I'm playing with the colored cubes and spheres, which I can see already came with programmed masses. 10s, 7s, 5, and 1s. But it seems they all push exactly the same. I've even increased their masses to 1000 and still get the same result. I even copied your code directly to see if I did something wrong. I could see you got way more resistance from the bigger shapes. With me that's not happening.
maybe because they are spheres, easier to push, but yes it's not a perfect method, it would be very difficult to get perfect physics interaction. this is just a simple method to apply some force when pushing against objects. as i said at the end, for more complex cases you would probably want to program it in yourself.
After I tried this my character in game is not moving when i try to move i am not receiving any errors but i can’t move my player character how do i solve this
can't think of why that would happen. you're talking about with the _push_away_rigid_bodies function? does it still work if you comment out the function call before move and slide? and you are still calling move_and_slide right?
@@MajikayoGames I went back through to check the move and slide and found out that the problem was i placed the function inside the physics process after moving the push rigid bodies function above the physics process it started working as intended
Thank you for tutorial! I have a strange issue that everything is working perfectly with small weights, but if I put it for example 30kg it is really hard to move, no matter what weight does my character have. Tried to play with friction option but it does not help. What could it be? Or I'm not seeng obvious? I'll provide a code snippet under that comment. Thanx in advance
## Debug prints #print("Direction: ", direction) #print("Velocity: ", velocity) #print("Player Velocity: ", player.velocity) #print("Target Rotation: ", target_rotation) #print("Mesh Root Rotation Y: ", mesh_root.rotation.y) func _push_rigid_bodies(): for i in player.get_slide_collision_count(): var c := player.get_slide_collision(i) if c.get_collider() is RigidBody3D: var push_dir = -c.get_normal() # How much velocity the object needs to increase to match player velocity in push direction var velocity_diff_in_push_dir = player.velocity.dot(push_dir) - c.get_collider().linear_velocity.dot(push_dir) # Only counts velocity towards push dir, away from character velocity_diff_in_push_dir = max(0., velocity_diff_in_push_dir) # Objects with bigger mass than us should be harder to push. But should not be pushed faster than we are moving
var mass_ratio = min(1., player.PLAYER_APPROX_MASS_KG / c.get_collider().mass)
Hello, I've used _push_away_rigid_bodies() function, put it before move_and_slide() all works good, but when I jump on the rigidbody3d object it behave very weird and glitchy (I try to stand on barrel mesh, so when Its moved and I jumped on it, barrel with pushed away very fast and fly away :D)
works flawlessly! i also strict height of collision with [if self.global_position.y - get_slide_collision(clsns).get_position(cldrs).y < 0.9:] so i got no issues with walking on little objects
im trying to get this code to stop working if the player is above or on top of the object because if i stand on an object they will start to get impulses until the object like explodes and i go flying off of it lol UPDATE: put this after push_dir for more better accurate results without glitches and launching in the air if abs(push_dir.y) > 0.1: # Adjust this threshold if needed continue
Love the ending bc is true I tried to do a 3D breakout bc it was "simple" and I almost end up, calculating all normals and velocities by hand xD, at the end I conformed myself with a decent result and left it as a nice prototipe of a simple game that I will polish if necessary, but physics took me by surprise when they are part of the gameplay
Doing a 3d breakout now. Personally, I would recommend a characterbody for the ball and paddles just due to this. I'm using rigidbody's for the bricks. I want some of the bricks to slide. I can get them to move, but it doesn't feel right, so digging into that some.
I can finally implement physics in my game with character bodies. It was a big problem for me, cause I am not a coder, but i wanted it so bad! Learning something new everyday. Definitely like and subscribe.
Top tier 💯
Keep them coming I'm here for it, another amazing video!
Thanks, this worked great and was exactly what I needed. No other good answers for this that I could find.
Special thanks to you, I have looked around for physics interaction for a long time with no result.
You can get some funny results while playing around with the BOUNCE property on the RigidBody3D. Managed to launch myself into space again after colliding with two objects which had bounce set to 1. I saw Azathoth this time. Wouldn't recommend.
Funny that you upload this, was just messing around with your old source code earlier today to check if physics was applied to objects.
I've just used a rigid body for my character. I realize that I have made it harder on myself in some ways, but I can work around those issues and as a bonus I don't have to worry about making it possible for the character to be moved by a moving obstacle in physically accurate manner (i. e. character flies away after being hit by an oversized hammer) and weird collision issues such as character being stuck in the walls or whatever as the physics engine will do that work for me.
Yes this is definitely one possible solution, this could be good for a lot of games. I probably should have mentioned this in the video too. Like you said it could have some downsides but all depends on what type of game you're making.
@@MajikayoGames 3D platformer, actually.
What problems have you face using rigid body for your controller? Curious to know the ups and downs of each type for godot
Bro! You are my hero, thank you, your videos is exactly what I wanted!
:D more to come. going to keep building out this fps controller/game for a while.
@@MajikayoGames You're the man. ATM this is by far the best fps controller out there for Godot, and I've checked a lot of them.
thanks man! ive been getting used to godot and your videos are a great help. you're awesome!
awesome!! glad you're enjoying :)
Very nice! A good primer for rigidbody interactions.
It doesn't appear to be working. I don't have the weight shapes you have in the video. But I'm playing with the colored cubes and spheres, which I can see already came with programmed masses. 10s, 7s, 5, and 1s. But it seems they all push exactly the same. I've even increased their masses to 1000 and still get the same result. I even copied your code directly to see if I did something wrong. I could see you got way more resistance from the bigger shapes. With me that's not happening.
maybe because they are spheres, easier to push, but yes it's not a perfect method, it would be very difficult to get perfect physics interaction. this is just a simple method to apply some force when pushing against objects. as i said at the end, for more complex cases you would probably want to program it in yourself.
Do you have Idea how can Character body attach rigid body to itself or drag or pull it?
After I tried this my character in game is not moving when i try to move i am not receiving any errors but i can’t move my player character how do i solve this
can't think of why that would happen. you're talking about with the _push_away_rigid_bodies function? does it still work if you comment out the function call before move and slide? and you are still calling move_and_slide right?
@@MajikayoGames I went back through to check the move and slide and found out that the problem was i placed the function inside the physics process after moving the push rigid bodies function above the physics process it started working as intended
Thank you for tutorial! I have a strange issue that everything is working perfectly with small weights, but if I put it for example 30kg it is really hard to move, no matter what weight does my character have. Tried to play with friction option but it does not help. What could it be? Or I'm not seeng obvious? I'll provide a code snippet under that comment. Thanx in advance
extends Node
class_name MovementController
@export var player : Player
@export var mesh_root : Node3D
@export var rotation_speed : float = 8
@export var fall_gravity : float = 45
var direction : Vector3
var velocity : Vector3
var cam_rotation : float = 0
var player_init_rotation : float
var acceleration : float
var speed: float
func _ready():
player_init_rotation = player.rotation.y
func _physics_process(delta: float) -> void:
velocity.x = speed * direction.normalized().x
velocity.z = speed * direction.normalized().z
if not player.is_on_floor():
velocity.y -= fall_gravity * delta
player.velocity = player.velocity.lerp(velocity, acceleration * delta)
_push_rigid_bodies()
player.move_and_slide()
var target_rotation = atan2(direction.x, direction.z) - player.rotation.y
mesh_root.rotation.y = lerp_angle(mesh_root.rotation.y, target_rotation, rotation_speed * delta)
## Debug prints
#print("Direction: ", direction)
#print("Velocity: ", velocity)
#print("Player Velocity: ", player.velocity)
#print("Target Rotation: ", target_rotation)
#print("Mesh Root Rotation Y: ", mesh_root.rotation.y)
func _push_rigid_bodies():
for i in player.get_slide_collision_count():
var c := player.get_slide_collision(i)
if c.get_collider() is RigidBody3D:
var push_dir = -c.get_normal()
# How much velocity the object needs to increase to match player velocity in push direction
var velocity_diff_in_push_dir = player.velocity.dot(push_dir) - c.get_collider().linear_velocity.dot(push_dir)
# Only counts velocity towards push dir, away from character
velocity_diff_in_push_dir = max(0., velocity_diff_in_push_dir)
# Objects with bigger mass than us should be harder to push. But should not be pushed faster than we are moving
var mass_ratio = min(1., player.PLAYER_APPROX_MASS_KG / c.get_collider().mass)
# Don't push object from above below
push_dir.y = 0
var push_force = mass_ratio * 5.0
c.get_collider().apply_impulse(push_dir * velocity_diff_in_push_dir * push_force, c.get_position() - c.get_collider().global_position)
func _on_set_movement_state(_movement_state : MovementState):
speed = _movement_state.movement_speed
acceleration= _movement_state.acceleration
func _on_set_movement_direction(_movement_direction: Vector3):
direction = _movement_direction.rotated(Vector3.UP,cam_rotation + player_init_rotation)
func _on_set_cam_rotation(_cam_rotation : float):
cam_rotation = _cam_rotation
Hello, I've used _push_away_rigid_bodies() function, put it before move_and_slide() all works good, but when I jump on the rigidbody3d object it behave very weird and glitchy (I try to stand on barrel mesh, so when Its moved and I jumped on it, barrel with pushed away very fast and fly away :D)
same problem, found a way to fix it yet?
Probably forgot to change the Y value in push_dir Vector3 to 0
works flawlessly!
i also strict height of collision with
[if self.global_position.y - get_slide_collision(clsns).get_position(cldrs).y < 0.9:]
so i got no issues with walking on little objects
im trying to get this code to stop working if the player is above or on top of the object because if i stand on an object they will start to get impulses until the object like explodes and i go flying off of it lol
UPDATE:
put this after push_dir for more better accurate results without glitches and launching in the air
if abs(push_dir.y) > 0.1: # Adjust this threshold if needed
continue