Follow player 3d

Hello.

So im making an horror game but i made a enemy that should follow the player if its on the area3d.

Im not going to give the code i tried bc its buns but i did:

all triggered by is_chasing = true

Follow a tutorial,

after i tried %Enemy.position = %Player.position * SPEED2 ( worked but a lil bad)

and also i did that with the rotation (didnt work well….)

Can someone help me?? :, )

AND PLEASE NO AI I DONT WANT THAT ( also its minus baggy if its not ai : ) )

Old script:

extends CharacterBody3D

var health = 100
var SPEED2 = 0.85 # around 85 or 90
var is_chasing = false

func physics_process() :
  If is_chasing:

  %ENEMYJ1.global_position = %Character.global_position * SPEED2 *#speed2 is just slower and reaches to the player. It works but its a lil bad bc hes just following and after he stays into the same position bc speed2 its making him slower i think.*

  %ENEMYJ1.rotation = %body.rotation # *this is really bad bc he rotates the same as the player and not rotating like resident evil chasin system .*

func on_area3d_entered(area3d):
  Is_chasing = true

Sorry if in the replys i wrote with the ‘’’ but i wrongly clicked , i promise i wanted to press ```

Post your code and describe what it’s doing vs what you’re expecting it to do.

7 Likes

I just wrote the code in the post. I know its not full but as like its a demo it was like that.

But heres it:

‘‘‘‘ extends CharacterBody3D

Var health = 100

Var is_chasing = false

Func physics_process() ecc… :

If is_chasing:

%ENEMYJ1.global_position = %Character.global_position * SPEED2 *#speed2 is just slower and reaches to the player. It works but its a lil bad bc hes just following and after he stays into the same position bc speed2 its making him slower i think.*

%ENEMYJ1.rotation = %body.rotation # *this is really bad bc he rotates the same as the player and not rotating like resident evil chasin system .*

Func on_area3d_entered(area3d):

Is_chasing = true. ““““

I just want the same sytem as like resident evil uses for the zombies to chase the player.

I know they use ai but i just want the same functionality but without ai.

-The area3d is just for activating the is_chasing player.-

Code formatting backticks need to be on a separate line in order for formatting to work.

2 Likes

Wha- can you explain better (im just stupid not that i dont know i think???)

```
code
here
```

Result:

code
here
1 Like

Sorry.

But its understandable still right?? I hope so but if theres problem dont worry ask anything!

It’s very difficult to read, and it’s generally a nice gesture to try and make the information you present as easy to understand as possible, so others can actually try and help you. You can edit your previous posts and format the code properly.

8 Likes

Oki doki! : )

1 Like

Done.!

1 Like

It’s not that easy on a non-Qwerty keyboard to get this formatting to work with precision. I’m typing (from France…) on an Azerty keyboard, and there’s no direct key for what seems to be called ‘back-ticks’, nor for ‘tildes’ (another option, apparently, to get script formatting…). A ‘Code Format’ button in the Editor toolbar would be far better, in my opinion. Just sayin’. Peace. :slight_smile:

1 Like

Allow me to re-think the solution.
1 - The Area of the enemy detects the Player and set an internal variable with it.
2 - In process, if player is set,

2 b - try to turn to it (required turn speed parameter) and

2 c - if the angle from the forward of the enemy to the player is less or equal some parameter will move up to a parameter defined speed on the calculated direction (from the enemy to the player) up to

2 c - a minimum distance parametrized used to attack

Is something like this what you’re trying to do?

2 Likes

C’est ça : image

Aussi : Ctrl+E

Désolé, mon français est merde.

1 Like

OK, I just tested it, and IT WORKED..! Thanks, it will make posting code so much easier. No more ‘back-ticks’ or whatever, just the ‘</>’ button to select before pasting in the code. Thanks; is the expression ‘Every day is a school day’..? :slight_smile:

(I’m not French, just British living in France…)

2 Likes

The American version of the expression is “You learn something new every day!”

I’m jealous.

2 Likes
just press the </> button
1 Like

So yeah! But theres no problem with the attack bc i can do that but you are right!!! : )

1 Like

Use look_at() instead of copying the rotation property.

Thanks i didnt tought about that​:smiling_face_with_tear: Now the rotation works but the movement still needs fixing bc its buns…
Just explaining how the movement is working:
The character isnt following him but its like copying the position. (As like it did with the rotation) THANKS A LOT THO bc i really forgot about look_at() that i just randomly used the same rotation​:smiling_face_with_tear: