Hi, I'm trying to make a 3D football game, and to kick the ball I'm trying to use apply_impulse() (obviously if this is not the best way, that can be changed)
The only issue is that I don't understand physics all too well, and I don't know what parameters I need to pass in, in order to apply an impulse that takes into account the player's rotation degrees, and therefore ends up 'kicking' the ball in the direction the player is facing. There is also literally no tutorial videos that end up including this or forum questions from what I can see, so I'm a little bit in the dark and alone despite knowing that other people have definitely been through this as well lol.
If anyone can put some code that would end up kicking the ball off in the direction the player is facing, that would be amazing, but any help at all is greatly appreciated! 🙂
Applying an impulse to a RigidBody3D based on rotation
Asked Answered
Looks like you need a forward vector.
Document: https://docs.godotengine.org/en/stable/tutorials/3d/using_transforms.html#obtaining-information
var football : RigidBody3D
var player : Node3D
var impulse_power : float = 100.0
func _kick(football : RigidBody3D):
var forward : Vector3 = player.get_global_transform().basis.z
football.apply_impulse(forward * impulse_power)
Sectary I've put this in but it's saying the apply_impulse function now has too few arguments?
I ended up changing it to:
as the second argument also needed to be a vector3, and then flipped the forwards vector, which seems to be working.
Thank you so much for the help though- a push in the right direction was all I needed 🙂
Sectary In Godot the forward vector is -basis.z and not basis.z.
© 2022 - 2024 — McMap. All rights reserved.