My enemy scene is bugging out and I'm lost...

JemberryJemberry Posts: 2Member
edited November 21 in Programming

My enemy script extends this code:

extends KinematicBody2D
class_name Actor

const FLOOR_NORMAL: = Vector2.UP
var _velocity: = Vector2.ZERO
export var gravity = 1000.0
export var speed = Vector2(90.0, 300.0)

And contains this:

extends "res://scripts/Actor.gd"

func _ready() -> void:
_velocity.x = -speed.x

func _physics_process(delta: float) -> void:
_velocity.y += gravity * delta
if is_on_wall():
change_direction()
_velocity.y = move_and_slide(_velocity, FLOOR_NORMAL).y

func change_direction():
_velocity.x *= -1.0
#plus a script for flipping the sprite

I works as intended, but it's too fast (as fast as the player!). So I added this to the ready function:

func _ready() -> void:
speed.x = 60.0 #It was 90.0 in the Actor script.
_velocity.x = -speed.x #This was here before.

And it totally bugged out! I don't know how to safely reduce the speed of the enemy. Help?

Before:

After:

It runs at 60fps in game, the recording software is slow.


Tags :

Answers

  • cyberealitycybereality Posts: 1,086Moderator

    Not sure but I notice you are using "velocity" and "_velocity", are they supposed to be the same variable? Also, when you export vars, I believe you need to set them in the inspector in the editor (which overrides the value in the script).

  • JemberryJemberry Posts: 2Member

    Hmm, I changed the value in the enemy's inspector and it bugged again. I changed it in the Actor script and the player characters slowed down. I gave the enemy a copy of the variables and disconnected it from the Actor script. If I set speed.x to anything other than 90.0 it bugs. I think I'll make a new scene and follow a tutorial to get something that works. I fixed the typo, but that wasn't the issue either.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file