#Velocity X Animation (Simple)

153 messages · Page 1 of 1 (latest)

buoyant crater
#

can you show your code?

vapid jay
#

yeah

#
    var input_vector = Vector3.ZERO

    if Input.is_action_pressed("move_forward"):
        input_vector.z += 1  
    if Input.is_action_pressed("move_back"):
        input_vector.z -= 1
    if Input.is_action_pressed("move_left"):
        input_vector.x += 1
    if Input.is_action_pressed("move_right"):
        input_vector.x -= 1


    input_vector = input_vector.normalized()


    # Convert input to world-space based on the mesh's rotation
    var world_movement = mesh.global_transform.basis * input_vector
    world_movement.y = 0  # keep movement flat on ground


    # Apply movement (X and Z only, leave Y for gravity)
    linear_velocity.x = world_movement.x * move_speed
    linear_velocity.z = world_movement.z * move_speed
vapid jay
#

var speed = linear_velocity.length()

#

to measure speed

buoyant crater
#

it seems like you're using a rigidbody, is that correct?

vapid jay
#

Yes

buoyant crater
#

you want to move rigidbodies by applying forces, you don't generally modify the linear_velocity value

#

this is also discouraged in the docs for rigidbodies

vapid jay
#

wait

#

im making a character than moves

#

should i use rigidbody or smth else?

buoyant crater
#

generally a characterbody is recommended for player-controlled characters

#

it's not impossible to use a rigidbody, and people do use them, but you'll just have more up-front work to get the rigidbody to move in a responsive-feeling way if it's a player character

vapid jay
#

Oh

vapid jay
#

i have rigidbody code (120 lines)

buoyant crater
#

there's a template for characterbodies that you can pull from

vapid jay
#

oh where can i get that from

buoyant crater
vapid jay
#

Oh

buoyant crater
#

when you create a script for a characterbody

#

it's very simplistic but it'll give you an idea of how you move a characterbody and can be built on from there

#

just about any tutorial out there dealing with player characters in godot is also going to use a characterbody

vapid jay
#

do i delete the rigidbody?

buoyant crater
#

you can change it to a characterbody by right clicking on it and selecting "change type"

#

you'll have to detach the old script too

vapid jay
#

Oh

#

theres no "change type

buoyant crater
vapid jay
#

this is what i have done

#

oh wait nvm

#

my bad

#

ok i changed it

#

do i delete rigidbody script?

buoyant crater
#

no need to, just detach it from your node if it's no longer a rigidbody

#

it's still useful for your reference for now

#

eventually you can delete it though

vapid jay
#

its not letting me add a template

#

oh ok i think i fixe dit

#

alr its working but

#

i need to add the moving screen code

#

will this still work:

#
var mouse_sensitivity := 0.0038
var twist_input := 0.0
var pitch_input = 0.0

@onready var twist_pivot := $TwistPivot
@onready var pitch_pivot := $TwistPivot/PitchPivot

# mouse lock toggle
    if Input.is_action_pressed("lock_mouse"):
        if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
            Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
        else:
            Input.mouse_mode = Input.MOUSE_MODE_CAPTURED

    # rotate camera pivots
    $TwistPivot.rotate_y(twist_input)
    pitch_pivot.rotate_x(pitch_input)
    pitch_pivot.rotation.x = clamp(
        pitch_pivot.rotation.x,
        deg_to_rad(-65),
        deg_to_rad(65)
    )
    # make the mesh face the camera's direction
    mesh.rotation.y = lerp_angle(mesh.rotation.y, twist_pivot.rotation.y + PI, 8 * delta)
    
    # reset inputs after applying rotation
    twist_input = 0.0
    pitch_input = 0.0


func _unhandled_input(event: InputEvent) -> void:
    if event is InputEventMouseMotion:
        if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
            twist_input = -event.relative.x * mouse_sensitivity
            pitch_input = -event.relative.y * mouse_sensitivity
            
            
#

i saved this before i deleted the old script

buoyant crater
#

it should, if all you did was just change the node type on your player scene

vapid jay
#

yeah

buoyant crater
#

you would probably know better than i would though, you're the one looking at your project 😛

vapid jay
#

im bad at this

#

but yeah ill work it out

buoyant crater
#

you may be able to check out this video: https://www.youtube.com/watch?v=ke5KpqcoiIU

#

people do recommend brackeys pretty strongly

vapid jay
#

Oh thx alot

#
    mesh.rotation.y = lerp_angle(mesh.rotation.y, twist_pivot.rotation.y + PI, 8 * delta)```
#

this part isnt working

#

wait

#

ohh

#

nvm

#

can i screenshare smth rq to u?

#

@buoyant crater 🙏

buoyant crater
#

sorry, i'm not available for screen share

vapid jay
#

ok ig i can just explain it here

#

ok so

#

The starting point of the body (the way its facing). lets say its north.
when i try to move my body (WASD), it only moves in that direction that its facing (north)
but if i move my screen to the south, it moves the opposite way. for example i press W, it moves back.

#

u understand me?

buoyant crater
#

sounds like maybe you're moving in the same absolute direction?

vapid jay
#

yeahh, its not changing when i move my screen

buoyant crater
#

usually you just need to multiply your input vector by your character's facing

#

something akin to:

var acceleration = 10.0
var speed = 100.0
var input_vector = Input.get_vector("left", "right", "forward", "back")
var direction = (transform.basis * Vector3(input_vector.x, 0, input_vector.y)).normalized()
velocity = velocity.move_toward(direction * speed, acceleration * delta)
#

as an example

#

input_vector is the player input (with wasd or whatever, really. those are input actions you would generate), speed is the character's top speed, acceleration is how fast the character, well, accelerates

#

velocity is a variable built into characterbodies that it uses when you call move_and_slide() to know where and how far it should move in a given frame

vapid jay
#

Oh ok thx alot 🙏

#

@buoyant crater hey i got a small question

#

im follwing the toturial

#

but

#

idk why, when i move my player or my screen

#

the floor or player glitches

#

its not smooth

#

idk why

buoyant crater
#

i'm not sure what you mean, sorry

vapid jay
#

like the movement

#

is glitchy

#

and not smooth

#

idk how to explain it well 😭

buoyant crater
#

can you maybe provide a screen recording or something?

#

maybe somebody is available to help out in the help desk too

vapid jay
#

i dont have a screen recorder on my computer 😭

buoyant crater
#

obs is free

vapid jay
#

Yeah but i dont have alot of storage on my computer

#

😔

buoyant crater
#

idk then haha

#

like I said, maybe somebody is available in the help desk

vapid jay
#

I hope so

forest sigil
#

If you don't have storage, do you have memory? I can't imagine a modern computer functioning without enough harddrive space to store a 10s video ...

vapid jay
#
  1. main one, barley has anything
#
  1. has alot of space but some apps dont let me download on it
#

ill try downloading one on the 2nd drive

forest sigil
#

What are you downloading?

#

Are you on windows? Windows has a built-in screen recorder

vapid jay
#

I am on windows

#

windows + g does nothing for me

#

ill just try to download obs

forest sigil
#

Print screen. Just swap it to video, select the region, and record.

vapid jay
#

@buoyant crater hey

#

how do i make my camera have a maximum angle i can look up or down at

#

oh wait

#

i got it

#

sorry

#

But another question

#

i have a rigidbody3d, that is shaped like a ball

#

which i touch it

#

it isnt moving like a rigidbody

#

why?

buoyant crater
#

i don't really know what you mean by that in this context

#

you can use layers and masks to make it so that the characterbody can push the rigidbody easily, but it is necessarily going to act as though the rigidbody is weightless even if it is not

#

more complex interactions are going to require some amount of code and effort to do

vapid jay
#

Red: Ball
Blue: me/player
when the player touches the ball, it doesnt move

#

i want it to move

#

how can it be possible?

#

cuz dont rigidbody's move normally?

#

(ball)

buoyant crater
#

right, so this is what i was saying before - you can get a characterbody to move a rigidbody through the use of layers and masks

vapid jay
#

layers and masks?

buoyant crater
#

in short, physics objects have layers and masks to determine what can interact with what

#

layer = where i am
mask = what i see

#

if an object's (A) set of masks has at least one bit in common with another object's (B) set of layers, A is said to be able to "see" B and thus collide/interact with it

#

if you make it so the rigidbody "sees" the characterbody, but the characterbody does not "see" the rigidbody, it will be able to push the rigidbody around easily

#

so, you may make it so the rigidbody is on layer 2, but has a mask of 1

#

and the characterbody is on layer 1, with a mask of 1

vapid jay
#

how do i set the layers and masks

#

oh i found it i think

buoyant crater
#

it is in the inspector under "Collision"

#

yeah

vapid jay
#

yo it worked 🔥

#

damnn i understand it noww

#

thx dude

#

is there anyway to make the game multiplayer?

#

or test it in multiplayer?

#

@buoyant crater

buoyant crater
#

mayyyyybe just focus on figuring out the workflow at this point

#

multiplayer tends to need to be designed from the ground up in your game architecture

#

also you don't have to keep pinging me here, haha. the beginner chat is also full of helpful people

vapid jay
#

im thinking of making a 1st person shooter game

buoyant crater
# vapid jay Yeah, im sorry!

it's all good, just been doing some work around the house and stuff like that in the meantime so i can't respond as quickly as other people may be able to at this point 🙂

vapid jay
#

Oh Nice