Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

character istn climbing stairs #6

Open
MiguelDevelopper opened this issue Oct 4, 2024 · 0 comments
Open

character istn climbing stairs #6

MiguelDevelopper opened this issue Oct 4, 2024 · 0 comments

Comments

@MiguelDevelopper
Copy link

my character dont climb the stairs even with a step of 1 meter

extends StairsCharacter

@export var state : Label

#player vars
@export var SPEED = 1.67
@export var JUMP_VELOCITY = 4.5
@export var RUN_MULTIPLIER = 2.994
@export var SENSIVILITY = 0.01
var canMove = true

# camera vars
var tps_mode = false
var lastTps = "rigth"
@onready var fps_pos = $"fps"
@onready var tps_pos1 = $"tps"
@onready var tps_pos2 = $"tps2"
@onready var camera = $Camera3D

#inventory vars
@onready var inventoryUi = $inventory
@export var inventory : Inventory

func _ready() -> void:
	Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

func _process(delta: float) -> void:
	if canMove:
		if Input.is_action_just_pressed("Change_View"):
			if tps_mode:
				var tween = get_tree().create_tween().set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_OUT)
				tween.tween_property(camera, "position", fps_pos.transform.origin, 0.4)
				tps_mode = false
			else:
				var tween = get_tree().create_tween().set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_OUT)
				if lastTps == "rigth":
					tween.tween_property(camera, "position", tps_pos1.transform.origin, 0.4)
				else:
					tween.tween_property(camera, "position", tps_pos2.transform.origin, 0.4)
				tps_mode = true
			
		const POSITION_TOLERANCE = 0.01
	
		if tps_mode:
			if Input.is_action_just_pressed("view_side_left"):
				if camera.global_transform.origin.distance_to(tps_pos2.global_transform.origin) > POSITION_TOLERANCE:
					var tween = get_tree().create_tween().set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_OUT)
					tween.tween_property(camera, "position", tps_pos2.transform.origin, 0.4)
					lastTps = "left"
			elif Input.is_action_just_pressed("view_side_Rigth"):
				if camera.global_transform.origin.distance_to(tps_pos1.global_transform.origin) > POSITION_TOLERANCE:
					var tween = get_tree().create_tween().set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_OUT)
					tween.tween_property(camera, "position", tps_pos1.transform.origin, 0.4)
					lastTps = "rigth"
	if Input.is_action_just_pressed("inventory"):
		if inventoryUi.visible != true:
			inventoryUi.visible = true
			Input.set_mouse_mode(Input.MOUSE_MODE_CONFINED)
			canMove = false
		else:
			inventoryUi.visible = false
			Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
			canMove = true

func _unhandled_input(event: InputEvent) -> void:
	if event is InputEventMouseMotion:
		$".".rotate_y(-event.relative.x * SENSIVILITY)
		camera.rotate_x(-event.relative.y * SENSIVILITY)
		camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-60),deg_to_rad(60))

func _physics_process(delta: float) -> void:
	
	# Add the gravity.
	if not is_on_floor():
		velocity += get_gravity() * delta
	
	if canMove:

		# Handle jump.
		if Input.is_action_just_pressed("ui_accept") and is_on_floor():
			velocity.y = JUMP_VELOCITY

		# Get the input direction and handle the movement/deceleration.
		# As good practice, you should replace UI actions with custom gameplay actions.
		var input_dir := Input.get_vector("Move_Left", "Move_Rigth", "Move_Foward", "Move_Backward")
		var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
		if direction:
			if Input.is_action_pressed("Run"):
				if state:
					state.text = "RUNING"
				velocity.x = direction.x * (SPEED * RUN_MULTIPLIER)
				velocity.z = direction.z * (SPEED * RUN_MULTIPLIER)
			else:
				if state:
					state.text = "WALKING"
				velocity.x = direction.x * SPEED
				velocity.z = direction.z * SPEED
		
		else:
			velocity.x = move_toward(velocity.x, 0, SPEED)
			velocity.z = move_toward(velocity.z, 0, SPEED)
	else:
		velocity.x = move_toward(velocity.x, 0, SPEED)
		velocity.z = move_toward(velocity.z, 0, SPEED)
	desired_velocity = velocity.normalized()
	move_and_stair_step()

im doing something wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant