0 votes

I'm trying to make a 2d platformer where you spawn an object and try to jump on it in the air before it falls.

the problem is when I try to spawn the tile it doesn't spawn where Is the cursor at
it adds a relative value to the position that I don't know how to get rid of it.

you see when I try to instance a scene it takes the cursor position and viewport value into account but then something happens and I fount the object spawning way too far.

see where is the cursor at and where did the tile spawn

, same thing here

and here

here is how I'm grouping the nodes and scenes

and this is the script I'm using, it's in the player1 scene

extends KinematicBody2D
# 

var score : int = 0

export var speed : int = 200
export var jumpforce : int = 600
export var gravity : int = 800

onready var AB1 = preload("res://player1AB.tscn")

var vel :Vector2 = Vector2()

onready var sprite : Sprite = get_node("sprite_idile")
onready var ui : Node = get_node("/root/mainscene1/CanvasLayer/ui")
onready var audioplayer : Node = 

getnode("/root/mainscene1/Camera2D/audioplayer")

func _physics_process(delta):
    vel.x = 0

    # movement inputs
    if Input.is_action_pressed("move_left"):
        vel.x -= speed
    if Input.is_action_pressed("move_right"):
        vel.x += speed

    # applying the velcoty
    vel = move_and_slide(vel,Vector2.UP)

    #apllying gravty
    vel.y += gravity * delta

    #jump input
    if Input.is_action_just_pressed("jump") and is_on_floor():
        vel.y -= jumpforce

    # where the sprite facing
        if vel.x < 0:
        sprite.flip_h = true
    if vel.x > 0:
        sprite.flip_h = false

    if Input.is_action_just_pressed("restart"):
        death()


func death ():
    get_tree().reload_current_scene()


func collect_coin (value):
    score += value
    ui.set_score_text(score)
    audioplayer.play_coin_sfx()


func _input(event):
    if event.is_action_pressed("click"):
        var ABT1 = AB1.instance()
        add_child(ABT1)
        var XN = null
        XN = get_viewport().get_mouse_position()  

        ABT1.position = XN

the important stuff

onready var AB1 = preload("res://player1AB.tscn")

func _input(event):
    if event.is_action_pressed("click"):
        var ABT1 = AB1.instance()
        add_child(ABT1)
        var XN = null
        XN = get_viewport().get_mouse_position()  
        ABT1.position = XN

this the same problem in Godot form check it out if possible in case someone answered there

https://godotforums.org/discussion/27007/my-get-viewport-get-mouse-position-isnt-working-right#latest

Godot version 3.3.2
in Engine by (16 points)

Guess you need to use TileMap.map_to_world and its counterpart Node.to_globalenter link description here

1 Answer

0 votes

https://stackoverflow.com/a/68538164/16529873

someone answered me there and helped me In a way that would make it easy to port the game to mobile so I went with his way.
but he also mentions the stretch mode as well but I really have no idea what that means so I need to look into that.
but thank you guys a lot in the worst case you helped me know how to debug my game and look for what is the problem.
but you showed me how great is this community cuz this is my first time doing it but I'm really impressed I thought I would need to pay someone to help me with that like a coach or something so thank you all again

by (16 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 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 webmaster@godotengine.org with your username.