Getting Rigid body to shoot in direction of node?

RungasahRungasah Posts: 1Member
edited March 6 in 3D

Hey guys,
I'm trying to shoot 3D Rigidbody bullets, i can spawn them in the correct rotation, but can't seem to get the bullets to travel forward on their local 3d coordinates, they'll only move on the global axis.

I've been trying to fix this for a few hours with no luck. I've been using Python for about a year but it's only my 3rd day using Godot so my code might be a little sloppy.

Any help would be awesome

Code is called through _physics process:


func fire(delta):

var position = get_node("/root/Spatial/Player/Head/Camera/BulletSpawnLocation").global_transform.origin
var rotationvar = get_node("/root/Spatial/Player/Head/Camera/BulletSpawnLocation").global_transform.basis

var BulletInstance = BulletScene.instance()

BulletInstance.transform.basis = rotationvar                        #Rotates bullet to orientation of gun
BulletInstance.set_translation(position)                            #Spawns bullet at end of gun
BulletInstance.apply_impulse(Vector3.ZERO,Vector3(0,0,0))       #Gives bullet velocity on spawning
get_tree().get_root().add_child(BulletInstance)                     #Spawns bullet

Comments

  • cyberealitycybereality Posts: 927Moderator

    Looks like your need to give the bullet some velocity (you are setting it to zero).

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file