How do i use the apply_impulse method?
Asked Answered
H

3

0

I keep trying to use it but an error says that the node does not contain a definition for it.

Hearty answered 11/12, 2023 at 16:34 Comment(0)
S
0

apply_impulse is a method on Rigidbody2D and RigidBody3D.

If you create a new scene chose one of these for objects you want to apply impulses too or make your script extend from Rigidbody2D/3D

class_name ExampleName extends Rigidbody3D

https://docs.godotengine.org/en/stable/classes/class_rigidbody2d.html
https://docs.godotengine.org/en/stable/classes/class_rigidbody3d.html

Example:

class_name Ball extends RigidBody3D
	
func throw(direction: Vector3):
	apply_central_force(direction * 300) # or in your case impulse

class_name is optional

Shiva answered 11/12, 2023 at 21:23 Comment(0)
S
0

Shiva Sorry, I always overlook the CSharp tag.
But the rigidbody part should also apply for this.

Shiva answered 11/12, 2023 at 21:27 Comment(0)
H
0

Shiva Thanks!

Hearty answered 12/12, 2023 at 10:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.