Shooting bullets in TowerDefense

hi, I’m doing a tower defense and I wanted to make my towers shoot towards the enemy, but without using the look_at() function, as I don’t want them to look at the enemy, does anyone know how to do this?

The look_at function is just to rotate the object to look at the position you want to. Do you want to move the bullets towards the enemy ? Dont really understand this

yes, i want the bullet goes toawards the enemy

velocity = position - enemy.position # this code in your _physics_update(delta) function lets the bullet follow the enemy

move_and_slide()

idk why, but this is not working with me

that’s my code:

extends CharacterBody2D

var enemy_preload = preload(“res://enimigo.tscn”)
var enemy = enemy_preload.instantiate()

var speed = 400
var Velocity

func _physics_process(delta):
Velocity = position - enemy.position
translate(Velocity.normalized() * speed * delta)
move_and_slide()

I put it on bullet script

i think the problem is your Velocity. The inbuild velocity starts with a lowercase v.

The never use your calculated Velocity. In Godot 4 you dont need to put the velocity manually to move_and_slide(). But tho you create a “new” Velocity, because its case sensitive, you never give it to move_and_slide().

Change Velocity to velocity

1 Like

Thank you, it was just a problem on my project

1 Like