This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
–1 vote

I want to use normalized but with different speeds for the side movement I saw a tut where you times the vector3 in "move and slide" but that only provides one type of movement instead of the sides being slower and front and back being faster, also has an issue where the players speed isnt getting applied and it moves very slowly when I use movement = movement.normalized.

here is the code:

in Engine by (164 points)

Thanks for posting your code. I don't have a place to run it right now, but here are a couple of observations

1) When you used .normalized() it scales the vector to have a length of 1 in any direction. In your code, you are setting your movement vector based on your movementspeed* variables, but then you apply .normalized after that which will set the vector to the same length in any direction. In your case, I do not think you need to used normalized - you would only need that if you want to convert a vector with varying length to a direction. In your case you want a vector with varying length depending on the speed in each direction.

2) ​in physicsprocess(delta) you are calling input(delta). The variable delta is the time since the last frame, but _input expects an input event object, so that is not going to work. Godot will automatically call your _input function with events when they happen so you do not need to call it yourself from _physicsprocess

I got told normalized stops the player from going faster when two keys are pressed e.g (a,d) so I would like to implement normalized so it stops the play from gaining speed/going faster sideways how would I stop that without normalized.

Ok, now I understand the problem...

Yes, you are right - assuming you had equal movement in all directions (your example does not) - for example right = (1,0) and down = (0,1) - selecting both together means you move (1,1) on a diagonal which has length = 1.41. So, the player moves further when 2 keys pressed. Normalize will stop that by setting the length of the diagonal vector to 1, so that makes your right (0.71,0) and down (0,0.71).

In your case, you want a movement of 15 for forward, or 8 for other directions but normalize will set the speed in all directions to 1 (or 0.71 if moving diagonally), so this will cancel the effect of your movementspeed*

You could move the speed calculation after the normalize.

To account for the faster speed when moving forward, you would need to increase that move when you scale
Maybe something like this (I have not tested this in 3d, so it might have errors)

var movement = Vector3()
var movement_speed = 8  
var forward = false

var mouse_sen = 0.3

func _ready():
func _physics_process(delta):
    if Input.is_action_pressed("ui_cancel"):

    var direction = Vector3()

    if Input.is_action_pressed("ui_up"):
        direction += -transform.basis.z 
        forward = true   # temporary flag to track that movement includes a forward element
        forward = false

    if Input.is_action_pressed("ui_down"):
        direction += transform.basis.z 
    if Input.is_action_pressed("ui_left"):
        direction += -transform.basis.x 
    if Input.is_action_pressed("ui_right"):
        direction += transform.basis.x 

    direction = direction.normalized() # this will always be length of 1 but you need it longer when moving forward
    if forward:
        direction += -transform.basis.z   # Double speed if moving forward, after normalizing
    movement = direction * movement_speed
    movement = move_and_slide(movement,Vector3.UP)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.