Rotation value is reset
Asked Answered
T

6

0

I add enemies to the scene and set rotation for them, but in debug, the rotation value is reset. how can I fix it?

Triptych answered 9/3 at 11:50 Comment(0)
T
0

Triptych A script is probably controlling. Look what scripts in the enemy scene are doing.

Taxidermy answered 9/3 at 12:42 Comment(0)
T
0

Taxidermy

there is nothing here that could change his rotation when he stands still

@onready var animation = $AnimationPlayer
@onready var player1: CharacterBody2D = get_tree().get_first_node_in_group("player") 
@onready var timer = $PathTimer
@onready var nav_agent = $NavigationAgent2D as NavigationAgent2D
@onready var RayCast = $RayCast2D
@export var speed = 100
var die = false
var remove_Ak = false
var direction

var state = WALK
enum {
  WALK,
  ATTACK,
  DIE
}
func _on_path_timer_timeout():
  move()


func move():
  $PlayerDetector/CollisionPolygon2D.rotation =  get_angle_to(player1.global_position) - 300
  $AnimatedSprite2D.rotation = get_angle_to(player1.global_position) - 300
  $AK2.rotation = get_angle_to(player1.global_position) - 300
  makepath()
  direction = to_local(nav_agent.get_next_path_position()).normalized()
  velocity = speed * direction

func makepath():
  nav_agent.target_position = player1.global_position

func _physics_process(_delta):
  move_and_slide()
  match state:
    WALK:
      walk_state()
    ATTACK:
      attack_state()
    DIE:
      die_state()
  if RayCast.is_colliding():
    state = ATTACK
  else:
    state = WALK
  

func walk_state(): if velocity == Vector2.ZERO: animation.play("Attack1_Idle") else: animation.play("Attack1_Walk") if die == true: die_state() func attack_state(): if velocity == Vector2.ZERO: animation.play("Attack1_Idle") else: animation.play("Attack1_Walk") if die == true: die_state() func die_state(): if remove_Ak == false: remove_child($AK2) remove_Ak = true z_index = 0 $CollisionShape2D.disabled = true $RayCast2D.enabled = false $PlayerDetector.monitoring = false $PlayerDetector.monitorable = false animation.play("Die") speed = 0 timer.stop() func _on_player_detector_body_entered(body): if body.has_method("player1"): timer.start() func _on_player_detector_body_exited(body): if body.has_method("player1"): timer.stop() velocity = Vector2.ZERO func _on_hurt_box_area_entered(_area): die = true
func _on_bullet_dedector_area_entered(area): $PlayerDetector/CollisionPolygon2D.rotation = get_angle_to(area.global_position) - 300~~~
Triptych answered 9/3 at 12:54 Comment(0)
T
0

Triptych Format your code properly using ~~~ tags.
There may be other scripts affecting it.

Taxidermy answered 9/3 at 13:4 Comment(0)
T
0

Taxidermy thanks) but what about my problem with rotation

Triptych answered 9/3 at 13:8 Comment(0)
T
0

Triptych there is nothing here that could change his rotation

Are you sure? Rotation is altered in move(). Put some print statement inside that function to see when it gets called. Also, as I already said, check that there are no other scripts that alter the rotation.

Taxidermy answered 9/3 at 14:40 Comment(0)
T
0

Taxidermy thanks) I noticed that one animation from Animation player 2D was changing the rotation parameter and deleted it

Triptych answered 9/3 at 14:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.