|Topic was automatically imported from the old Question2Answer platform.
Hey guys im new to Godot and im in the process of learning GDscript. I was following the document and tried to replicate the “Click and move” tutorial in the document, but for some reason my instance goes somewhere else, i even copied the doc code and tried it but still no dice. I ended up printing the mouse position and the target position, and they match and both are correct, but I think the “move_and_slide” is placing the coordinates somewhere else for some reason, is the doc out dated?
Heres a youtube link: https://www.youtube.com/watch?v=TmBRYtpkLEU
It’s not outdated. Can you provide more information? Like, what do you mean somewhere else?
exuin | 2020-10-02 05:20
like if you click 0,0 it goes to like 200,200
veridical | 2020-10-02 05:23
Is your scene the same as the example scene (only contains a kinematicbody2d with child collisionshape2d and sprite) or is it different?
exuin | 2020-10-02 05:27
its all exactly as it said to do, if i can find a way to show whats going on i will
veridical | 2020-10-02 05:30
I turned in into a youtube video lol its in the question now
veridical | 2020-10-02 05:40
You have the kinematicbody2d as a child of a node2d, which isn’t what is in the tutorial. The kinematicbody2d is the scene root in the tutorial. When the kinematicbody2d moves, it’s relative to the parent node. If you make the kinematicbody2d the scene root it should work properly.
exuin | 2020-10-02 06:03
How do i get rid of the node2d and not have it parent? also, can group them together so i dont have to click and drag? like can i group them all to the parent and just move the parent around? and then how do i change the starting position?
veridical | 2020-10-02 06:10
Right click the kinematicbody2d and click “make scene root”. Moving the parent around automatically moves the child nodes, too. You can disable selecting the child nodes by clicking the icon with the two squares to the right of the lock icon at the top bar of the view of the scene. And you can change the starting position by changing the position coordinates in the inspector or dragging the node around.
exuin | 2020-10-02 06:17
Sweet thanks! i still cant figure out how to change the starting position, i dragged it around but the instance still starts at 0,0, and then how to you make a new object with out it being a child of another? what if I wanted 2 bodies? thanks for helping out a godot noob
veridical | 2020-10-02 06:27
What is “it” you’re dragging around? Is it the kinematicbody2d? If you want a new object that’s a scene root, you should make a new scene. If you want two bodies, you can make two scenes and then instance them in a third scene using the chain icon in the scene panel.
exuin | 2020-10-02 06:30
yeah, i got rid of the node2d, locked them all to the parent (the kinebody) and dragged the body to the center of my view in the scene
veridical | 2020-10-02 06:36
What do you mean by it “starts at 0,0”? Do you mean the node moves to 0,0 upon running the scene or that it appears there when running the scene?
exuin | 2020-10-02 06:40
i mean that when you run the scene it starts at 0,0 instead of where i placed it, it moves to the mouse, but it shouldnt be starting in the top left if i placed it in the center
veridical | 2020-10-02 06:43
Okay, so do you have the player scene instanced in the main scene (from your youtube video)? If so, you need to change the position in the main scene, not on the player scene itself.
exuin | 2020-10-02 06:46
the player scene is the main scene, i only have the one scene right now
veridical | 2020-10-02 06:49
That’s weird. Are you sure that you moved the kinematicbody2d? Its position under transform isn’t still 0, 0?
exuin | 2020-10-02 06:54
Yep, and nope, its one 900,400 then when you run the scene it starts at 0,0. I wonder if the camera is shifting? but it shouldnt be, i didnt get that far into the docs yet, so i dont even have a camera, also if there called scenes, does that make them the room or the map? or just instance handlers? the entire scene situation seems very messy
veridical | 2020-10-02 06:58
The camera should only move if you have a camera node or if you transform the viewport yourself, but I don’t think you’re doing that. I wouldn’t say scenes are rooms or maps, they’re just instance handlers. I really have no clue what’s wrong with your project. Do you mind uploading it?
exuin | 2020-10-02 07:02
wait wait, i looked under the sprite transform, and for some reason its staying at 0,0 and not following the parents position…how do i upload the project lol
veridical | 2020-10-02 07:11
The sprite’s transform should be 0,0 relative to the parent. And you can upload the project to any file sharing website or github or something like that.
exuin | 2020-10-02 07:13
do you think the “target” vector is automatically being pre-set? if i can remember my git, ill be sure to upload it
veridical | 2020-10-02 07:16
Yes. The target vector is initialized at (0, 0). If you don’t want it to be (0, 0), you should put this in your ready function:
target = position
exuin | 2020-10-02 07:19
I thought so lol thanks!
veridical | 2020-10-02 07:22