Godot_v4.3-stable_win64###
Title: W, S, A, D Movement, Collision, and Preventing Passing Through Objects Issue
Hello Godot Community,
I’ve been working on a game using Godot 4.x, and I’m trying to implement a movement system with the following features:
W key to move upward (jump)
S key to move downward (descend)
A key to rotate around the character’s own axis to the right
D key to rotate around the character’s own axis to the left
In the process, I need the collision system to work correctly to prevent the character from passing through objects. Normally, when I apply gravity to objects, they don’t pass through each other, but with the code I’ve written, the character goes straight through objects when trying to rotate.
extends Node3D
Dönme ve hareket hızlarını ayarlayın
var rotation_speed = 2.0
var movement_speed = 5.0
func _ready():
# Başlangıçta bir şey yapmamıza gerek yok
pass
func _process(delta):
# move_up aksiyonuna basıldığında yukarı hareket
if Input.is_action_pressed(“move_up”): # ‘W’ tuşu
position.y += movement_speed * delta
# move_down aksiyonuna basıldığında aşağı hareket
if Input.is_action_pressed("move_down"): # 'S' tuşu
position.y -= movement_speed * delta
# move_left aksiyonuna basıldığında sola dönme
if Input.is_action_pressed("move_left"): # 'A' tuşu
rotate_y(-rotation_speed * delta)
# move_right aksiyonuna basıldığında sağa dönme
if Input.is_action_pressed("move_right"): # 'D' tuşu
rotate_y(rotation_speed * delta)
extends Node3D
const MOVE_LEFT = “move_left”
const MOVE_RIGHT = “move_right”
const MOVE_UP = “move_up”
const MOVE_DOWN = “move_down”
var speed = 5.0
func _physics_process(delta):
var direction = Vector3.ZERO
if Input.is_action_pressed(MOVE_UP):
direction.y += speed
if Input.is_action_pressed(MOVE_DOWN):
direction.y -= speed
if Input.is_action_pressed(MOVE_LEFT):
rotate(Vector3(0, 1, 0), speed * delta) # Y ekseninde dönüş
if Input.is_action_pressed(MOVE_RIGHT):
rotate(Vector3(0, 1, 0), -speed * delta) # Y ekseninde dönüş
# Hareketi position ile yapıyoruz
position += direction * delta