+1 vote
void PlayerController::spawn_bullet(Vector3 position, Vector3 direction, int speed) {
    ResourceLoader *resource_loader = ResourceLoader::get_singleton();
    Ref<PackedScene> res = resource_loader->load("res://ModelScenes/Bullet.tscn");
    KinematicBody *body = (KinematicBody *) res -> instance();
    body -> set_translation(get_transform().origin + position);
   // set direction variable defined other node object (c++ code variable) 
    get_parent() ->add_child(body)}

}

How can i access variable in the other object which i am instancing,

in GDScript it is
var node = bullet.instance()
node.direction = Vector3(1, 0, 0) // this is what i am talking about!
add_child(node)

How can i do this with GDNative C++ ?

Thank you in advance :)

in Engine by (45 points)

1 Answer

+2 votes
Best answer

Got solution

used body -> set("bullet_direction", Vector3(1, 0, 0));

by (45 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.