I’ve a characterbody3d that acts as a spaceship that I’ve quickly given motion utilizing the keyboard after which I’ve a characterbody3d that acts as a participant that I’ve positioned contained in the ship, however exterior the ship node. When the ship strikes, the participant ought to keep nonetheless as a result of it’s floating inside it, however when it collides with a wall of the ship (I’ve colliders3d for that), it ought to collide and observe the motion of the ship. What is going on to me now’s that the ship stops fully and the participant stays fully nonetheless. I am not superb at this, I am about 5 hours into godot and perhaps I am utilizing a characterbody3d for the ship when it must be one thing else or perhaps there is not any approach to do what I say routinely and I have to program one thing to do it. such an impact, I do not know. I take advantage of godot 4 and my query is extra to see how I strategy this to acquire the specified outcome. In case you want it, I can go the challenge on to you since it’s only a check, nothing extra.
I’ve tried a number of issues each in code and touching the properties of the objects and the colliders, however I can not get something
That is my node construction:
- Node3D
- Ship (Characterbody3D)
- Mesh
- Collider1 (represents one of many partitions of the ship)
- Collider2 (represents one of many partitions of the ship)
- Collider3 (represents one of many partitions of the ship)
- Collider4 (represents one of many partitions of the ship)
- Participant (Characterbody3D)
- Camera3D
- Collider1 (Capsule3D)
- Ship (Characterbody3D)
That is the code related to the characterbody3d that acts as a ship:
extends CharacterBody3D
@export var max_speed = 50.0 # FIXME velocidad de la luz 99%
@export var acceleration = 0.6
@export var pitch_speed = 1.5
@export var roll_speed = 1.9
@export var yaw_speed = 1.25 # Set decrease for linked roll/yaw
@export var input_response = 8.0
var horizontal_speed = 0.0
var vertical_speed = 0.0
var forward_speed = 0.0
var pitch_input = 0.0
var roll_input = 0.0
var yaw_input = 0.0
func get_input(delta):
# STRAFE LEFT AND RIGHT
if Enter.is_action_pressed("STRAFE_RIGHT"):
horizontal_speed = lerp(horizontal_speed, max_speed, acceleration * delta)
if Enter.is_action_pressed("STRAFE_LEFT"):
horizontal_speed = lerp(horizontal_speed, -max_speed, acceleration * delta)
# STRAFE FRONT AND BACK
if Enter.is_action_pressed("STRAFE_FRONT"):
forward_speed = lerp(forward_speed, max_speed, acceleration * delta)
if Enter.is_action_pressed("STRAFE_BACK"):
forward_speed = lerp(forward_speed, -max_speed, acceleration * delta)
# STRAFE UP AND DOWN
if Enter.is_action_pressed("STRAFE_UP"):
vertical_speed = lerp(vertical_speed, max_speed, acceleration * delta)
if Enter.is_action_pressed("STRAFE_DOWN"):
vertical_speed = lerp(vertical_speed, -max_speed, acceleration * delta)
# ROTATE LEFT AND RIGHT
if Enter.is_action_pressed("ROTATE_LEFT"):
yaw_input = lerp(yaw_input, yaw_speed, acceleration * delta)
if Enter.is_action_pressed("ROTATE_RIGHT"):
yaw_input = lerp(yaw_input, -yaw_speed, acceleration * delta)
# ROTATE UP AND DOWN
if Enter.is_action_pressed("ROTATE_UP"):
roll_input = lerp(roll_input, roll_speed, acceleration * delta)
if Enter.is_action_pressed("ROTATE_DOWN"):
roll_input = lerp(roll_input, -roll_speed, acceleration * delta)
# ROTATE UP AND DOWN
if Enter.is_action_pressed("TURN_LEFT"):
pitch_input = lerp(pitch_input, pitch_speed, acceleration * delta)
if Enter.is_action_pressed("TURN_RIGHT"):
pitch_input = lerp(pitch_input, -pitch_speed, acceleration * delta)
#pitch_input = lerp(pitch_input, Enter.get_axis("pitch_down", "pitch_up"), input_response * delta)
#roll_input = lerp(roll_input, Enter.get_axis("roll_right", "roll_left"), input_response * delta)
# yaw_input = lerp(yaw_input, Enter.get_axis("yaw_right", "yaw_left"), input_response * delta)
#yaw_input = roll_input
# TODO recoger también las pulsaciones directas con el ratón en los botones
func _physics_process(delta):
get_input(delta)
remodel.foundation = remodel.foundation.rotated(remodel.foundation.z, roll_input * roll_speed * delta)
remodel.foundation = remodel.foundation.rotated(remodel.foundation.x, pitch_input * pitch_speed * delta)
remodel.foundation = remodel.foundation.rotated(remodel.foundation.y, yaw_input * yaw_speed * delta)
remodel.foundation = remodel.foundation.orthonormalized()
velocity = (-transform.foundation.z * horizontal_speed) + (-transform.foundation.x * forward_speed) + (remodel.foundation.y * vertical_speed)
#move_and_collide(velocity * delta)
move_and_slide()
#if move_and_collide(velocity * delta):
# for i in get_slide_collision_count():
# var col = get_slide_collision(i)
# if col.get_collider() is CharacterBody3D:
# col.get_collider().apply_force(col.get_normal() * 1000)
And that is the one with the participant who has a digicam with the script:
extends Camera3D
const ray_length = 1000
#@export var pushForce = 500
#@export var bodyPath: NodePath = ".."
#@onready var physique: CharacterBody3D = get_node(bodyPath)
var SENSITIVITY = 0.3
var v = Vector3()
func _ready():
Enter.set_mouse_mode(Enter.MOUSE_MODE_CAPTURED)
func _process(delta):
go
func _input(occasion):
if occasion is InputEventMouseMotion:
v.y -= (occasion.relative.x * SENSITIVITY)
v.x -= (occasion.relative.y * SENSITIVITY)
v.x = clamp(v.x, -80, 90)
#if occasion is InputEventMouseButton:
# if occasion.button_index == MOUSE_BUTTON_LEFT:
# if occasion.pressed:
# var digicam = $Camera3D
# var from = digicam.project_ray_origin(occasion.place)
# var to = from + digicam.project_ray_normal(occasion.place) * ray_length
# print("Hit at level: ", to.place)
func _physics_process(delta):
rotation_degrees.x = v.x
rotation_degrees.y = v.y
#if physique.move_and_slide(): # true if collided
# for i in physique.get_slide_collision_count():
# var col = physique.get_slide_collision(i)
# if col.get_collider() is CharacterBody3D:
#col.get_collider().apply_force(col.get_normal() * -pushForce)
#physique.velocity(col.get_normal() * -pushForce)