#Velocity X Animation (Simple)
153 messages · Page 1 of 1 (latest)
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
heres my movement code
var speed = linear_velocity.length()
to measure speed
it seems like you're using a rigidbody, is that correct?
Yes
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
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
Oh
Then can u help me set up characterbody instead
i have rigidbody code (120 lines)
there's a template for characterbodies that you can pull from
oh where can i get that from
Oh
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
do i delete the rigidbody?
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
this is what i have done
oh wait nvm
my bad
ok i changed it
do i delete rigidbody script?
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
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
it should, if all you did was just change the node type on your player scene
yeah
you would probably know better than i would though, you're the one looking at your project 😛
Im still a begginer 😂
im bad at this
but yeah ill work it out
you may be able to check out this video: https://www.youtube.com/watch?v=ke5KpqcoiIU
► Check out Zenva's free Godot course: https://academy.zenva.com/product/godot-101-game-engine-foundations/?utm_source=youtube&utm_medium=partner&utm_campaign=partner-youtube-brackeys-202501&utm_content=partner-youtube-brackeys-202501
► Get 20% off your first year (on top any existing site-wide discounts!) with this link (first 50 people): h...
people do recommend brackeys pretty strongly
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 🙏
sorry, i'm not available for screen share
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?
sounds like maybe you're moving in the same absolute direction?
yeahh, its not changing when i move my screen
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
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
i'm not sure what you mean, sorry
can you maybe provide a screen recording or something?
maybe somebody is available to help out in the help desk too
i dont have a screen recorder on my computer 😭
obs is free
I hope so
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 ...
i have 2 hard drives
- main one, barley has anything
- has alot of space but some apps dont let me download on it
ill try downloading one on the 2nd drive
What are you downloading?
Are you on windows? Windows has a built-in screen recorder
Print screen. Just swap it to video, select the region, and record.
@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?
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
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)
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
layers and masks?
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
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
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
Yeah, im sorry!
Okay
im thinking of making a 1st person shooter game
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 🙂
Oh Nice