Player not rotating in the direction hes moving Godot4.2.2

So im pretty new to godot and im trying to let my player rotate smoothly in the direction hes moving to.
Right now he just clips between the 8 possible moving directions, so im basicly trying to have a smooth transition between those directions. I tried a couple different things but none of them worked, most of the time the character just rotates permanently or in random directions

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>extends CharacterBody3D
const NormalSpeed := 180
const SprintSpeed := 360
const SneakSpeed := 90
const fall_acce := 60
const jump_impulse := 1000
var target_velocity := Vector3.ZERO
#-------------------------------------------------------------------------------
func _physics_process(delta):
#Stores the input direction
var direction := Vector3.ZERO
#just checking for input and BASIC moving based on that
if Input.is_action_pressed("m_forward"):
direction.x += 1
if Input.is_action_pressed("m_backward"):
direction.x -= 1
if Input.is_action_pressed("m_left"):
direction.z -= 1
if Input.is_action_pressed("m_right"):
direction.z += 1
#Normalizing
if direction != Vector3.ZERO:
direction = direction.normalized()
$Pivot.basis = Basis.looking_at(direction)
if not is_on_floor():
target_velocity.y = target_velocity.y - (fall_acce * delta)
#Extra Movement
#Sprint
var speed: int
if Input.is_action_pressed("m_sprint"):
speed = SprintSpeed
else:
speed = NormalSpeed
#Sneak
if Input.is_action_pressed("sneak"):
get_node("CollisionShape3D").disabled = true
speed = SneakSpeed
else:
get_node("CollisionShape3D").disabled = false
#Jump
if is_on_floor() and Input.is_action_just_pressed("jump"):
target_velocity.y = jump_impulse * delta
target_velocity.x = direction.x * speed * delta
target_velocity.z = direction.z * speed * delta
velocity = target_velocity
move_and_slide()
</code>
<code>extends CharacterBody3D const NormalSpeed := 180 const SprintSpeed := 360 const SneakSpeed := 90 const fall_acce := 60 const jump_impulse := 1000 var target_velocity := Vector3.ZERO #------------------------------------------------------------------------------- func _physics_process(delta): #Stores the input direction var direction := Vector3.ZERO #just checking for input and BASIC moving based on that if Input.is_action_pressed("m_forward"): direction.x += 1 if Input.is_action_pressed("m_backward"): direction.x -= 1 if Input.is_action_pressed("m_left"): direction.z -= 1 if Input.is_action_pressed("m_right"): direction.z += 1 #Normalizing if direction != Vector3.ZERO: direction = direction.normalized() $Pivot.basis = Basis.looking_at(direction) if not is_on_floor(): target_velocity.y = target_velocity.y - (fall_acce * delta) #Extra Movement #Sprint var speed: int if Input.is_action_pressed("m_sprint"): speed = SprintSpeed else: speed = NormalSpeed #Sneak if Input.is_action_pressed("sneak"): get_node("CollisionShape3D").disabled = true speed = SneakSpeed else: get_node("CollisionShape3D").disabled = false #Jump if is_on_floor() and Input.is_action_just_pressed("jump"): target_velocity.y = jump_impulse * delta target_velocity.x = direction.x * speed * delta target_velocity.z = direction.z * speed * delta velocity = target_velocity move_and_slide() </code>
extends CharacterBody3D

const NormalSpeed := 180
const SprintSpeed := 360
const SneakSpeed := 90

const fall_acce := 60

const jump_impulse := 1000

var target_velocity := Vector3.ZERO

#-------------------------------------------------------------------------------

func _physics_process(delta):
    
    #Stores the input direction
    var direction := Vector3.ZERO
    
    #just checking for input and BASIC moving based on that
    if Input.is_action_pressed("m_forward"):
        direction.x += 1
    if Input.is_action_pressed("m_backward"):
        direction.x -= 1
    if Input.is_action_pressed("m_left"):
        direction.z -= 1
    if Input.is_action_pressed("m_right"):
        direction.z += 1
        
    #Normalizing
    if direction != Vector3.ZERO:
        direction = direction.normalized()
        $Pivot.basis = Basis.looking_at(direction)
        
    
    
    if not is_on_floor(): 
        target_velocity.y = target_velocity.y - (fall_acce * delta)
        
    #Extra Movement
    #Sprint
    var speed: int
    if Input.is_action_pressed("m_sprint"):
        speed = SprintSpeed
    else:
        speed = NormalSpeed
        
    #Sneak
    if Input.is_action_pressed("sneak"):
        get_node("CollisionShape3D").disabled = true 
        speed = SneakSpeed
    else:
        get_node("CollisionShape3D").disabled = false 
        
    #Jump
    if is_on_floor() and Input.is_action_just_pressed("jump"):
        target_velocity.y = jump_impulse * delta
        
    
        
    
    target_velocity.x = direction.x * speed * delta
    target_velocity.z = direction.z * speed * delta
        
    
    
    velocity = target_velocity
    move_and_slide()

New contributor

Aluxus Alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật