rewrite this 3d code for me so I can move it around when I swap to 3d plane from 2d:…
- User
rewrite this 3d code for me so I can move it around when I swap to 3d plane from 2d:
extends CharacterBody3D
const MAX_LIFEPOINTS := 200
export var speed := 5.0 export var jump_velocity := 4.5 var _lifepoints: int = MAX_LIFEPOINTS setget , get_lifepoints
var gravity: float = ProjectSettings.get_setting("physics/3d/default_gravity") var _attackTimer: Timer var _visual: Node3D var _playerLifebar: ProgressBar var _animationTree: AnimationTree
func _ready(): _playerLifebar = get_tree().current_scene.get_node("HUD/PlayerLifeBar") _playerLifebar.max_value = MAX_LIFEPOINTS _playerLifebar.value = _lifepoints
_attackTimer = get_node("AttackCooldown") _visual = get_node("Visual") _animationTree = get_node("AnimationTree")
func get_lifepoints() -> int: return _lifepoints
func _process(delta: float) -> void: _playerLifebar.value = _lifepoints
func _physics_process(delta: float) -> void: var velocity := get_velocity()
Add gravity
if not is_on_floor(): velocity.y -= gravity * delta
Handle movement and deceleration
var input_dir := Vector2( Input.get_action_strength("move_right") - Input.get_action_strength("move_left"), Input.get_action_strength("move_back") - Input.get_action_strength("move_forward") ) var direction := (global_transform.basis.xform(Vector3(input_dir.x, 0, input_dir.y))).normalized()
if direction != Vector3.ZERO: velocity.x = direction.x * speed velocity.z = direction.z * speed else: velocity.x = lerp(velocity.x, 0, speed * delta) velocity.z = lerp(velocity.z, 0, speed * delta)
set_velocity(velocity) move_and_slide()
velocity.y = 0.0 _animationTree.set("parameters/walking/blend_amount", velocity.length())
if velocity.length() == 0.0: return _visual.look_at(get_global_transform().origin + 10 * velocity, Vector3.UP)
func _on_AttackTimeOut(): _attackTimer.start()
func take_damages(damages: int): _lifepoints = clamp(_lifepoints - damages, 0, MAX_LIFEPOINTS)
func heal(heal_amount: int) -> void: _lifepoints = clamp(_lifepoints + heal_amount, 0, MAX_LIFEPOINTS)
func _on_SwapPlane(): var sceneChangerScript = load("res://Scripts/Global/SceneChanger.gd") as Script var sceneChangerNode = get_node("SceneChanger") sceneChangerNode.call("change_to_2d")
my working 2dplane script:
extends CharacterBody2D class_name Player2D enum State { IDLE, RUN, JUMP, ATTACK } var state = State.IDLE var bullets_amount: int = 30 var attack_animation: String = "Attack1" var player_base = PlayerBase.new()# Use PlayerBase’s set_health method¨
@export var movement_data : MovementData @export var stats : Stats
References
@onready var animator : AnimatedSprite2D = ShootingAnimationPlayer @onready var hit_animator : AnimationPlayer = Hand @onready var pistol : Sprite2D = Hand/Pivot/Pistol/PistolBulletMarker @onready var attacking: bool = false @export var camera: Camera2D
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.