#what is affecting the x value of the object

1 messages · Page 1 of 1 (latest)

rugged sequoia
#

ok this is very very confusing, something is affecting the x value of the objects and i have no clue what it is, i set the object's velocity y value and the gravity to 0, and set their x velocity to the screen width, they should be moving across the screen in one second right, and when i change their width, the new objects change their speed but too much like there is something else deciding their overall x velocity

the objects are area2d

#

i have the gravity and y velocity set to 0 as u can see in the labels

trim scroll
#

Could you share the script the controls their velocity?

rugged sequoia
#
func spawn_object():
    # Instance the object scene
    var object_instance = object_scene.instantiate()
    # just setting a value for now, it'll be changed later
    var velocity = Vector2(1,1)
    
    # Get the current screen dimensions
    var screen_size = DisplayServer.window_get_size()
    # we take a reference for the resolution in godot
    var reference_resolution = Vector2(720, 1055)
    #vector2 scale factor calculation
    var scale_factor = Vector2(
        screen_size.x / reference_resolution.x,
        screen_size.y / reference_resolution.y)
    
    var unified_scale = (screen_size.x / reference_resolution.x + screen_size.y / reference_resolution.y) / 2
    
    
    # Randomly choose left or right side for spawn
    var spawn_side = 0.2  # Random value between 0.0 and 1.0, 0.2 for left_side debugging
    if spawn_side > 0.5:
        # Off-screen to the right with random height
        object_instance.position = Vector2(
            screen_size.x, 
            randf_range((screen_size.y * 0.3), (screen_size.y * 0.7))
        )
        velocity.x = -randf_range(500, 700) * (screen_size.x/720) # Move left with adjusted velocity
    else:
        # Spawn off-screen to the left
        object_instance.position = Vector2(
            -(screen_size.x),  # Dynamically adjust for the expanded width
            randf_range((screen_size.y * 0.3), (screen_size.y * 0.7))
        )
        velocity.x = screen_size.x  # Move right  # move right with adjust velocity
    
    
    
    #object scaling, object x velocity is set in the side section above
    object_instance.scale = object_instance.scale
    #setting y velocity based on screen size for simplicity
    velocity.y = -randf_range(500, 700) * unified_scale * 0
    
    velocity.x = velocity.x
    #setting gravity based on screen size for simplicity
    object_instance.gravity = screen_size.x * 0.8 * 0
    #setting the velocity to the object
    object_instance.velocity = velocity
    
#

the main issue i had was object's not behaving the same despite the resolution

#

i tried the scaling factor and the unified factor aswell

#

so thought i'd focus on one factor

#

the x value

trim scroll
#

Just to rule something out, what type of Node does this script extend?

hoary sundial
#

Are you saying you don't want screen size to affect the speed, i don't really understand the issue

rugged sequoia
#

it's the root node

rugged sequoia
#

but it's not consistent

hoary sundial
#

Are you sure, i counted and it was 1.5 - 1.75 secs

rugged sequoia
#

the speed is set to the screen width, it changes but too much

rugged sequoia
#

it's more when the width is low

hoary sundial
#

Well im not a perfect counter

#

im saying it seemed consistent just above a second

rugged sequoia
#

i mean when the width is super small, they clump up

hoary sundial
#

Well i think the issue there is, you dont have a function when adjusting screen size to update existing tomatos? (I think thats what they are) speed. It seems speed is only set when spawned

rugged sequoia
#

oh existing tomatos don't matter

hoary sundial
#

Well thats why they clump up

rugged sequoia
#

since the screen size won't change in the actual game

#

it's made for mobile, different resolutions

#

they clump since the spawn speed is same but the object speed gets very low

hoary sundial
#

So if you didnt touch the screen size, have you set a timer to count how fast it takes to reach from one end ot the other? Because when i counted it seemed consistent, just the fact the screen size kept chagne aka the speed kept changing

rugged sequoia
#

yeah the speed should change at the exact ratio of 1:1 to the screen size, and the label i have does show it that way aswell

#

like this is super small here

#

the screen width to velocity is 1:1 in every resolution

#

but not the same aswell

trim scroll
#

I noticed in the first video when your screen is the initial width, they complete their travel in 1 second. When you stretch it wider, they complete their travel in 1 second. But when you shrink it much smaller than the initial width, they take much longer than 1 second

#

So this issue does not happen for stretching larger than your initial width, only for shrinking smaller than your initial width

rugged sequoia
#

imma try something

trim scroll
#

What are your project settings under Window > Stretch? I suspect that has something to do with it

rugged sequoia
#

expand

#

to keep the ui size proper

trim scroll
#

What is the mode?

rugged sequoia
#

viewport

trim scroll
#

I suspect you want to retry this in canvas_items mode

rugged sequoia
rugged sequoia
trim scroll
#

Yea, I don't super understand those modes myself, so I could totally be wrong

rugged sequoia
#

it's the same in canvas, haven't read about it yet tho

#

waait

#

omg

#

they were slower on lower width, faster on longer width...

so i adjusted the speed accordingly

i just tried with keeping the speed at 600 for this

#

what is velocity even based on if not pixels?

trim scroll
#

It is based on pixels in 2D, but depending on how your stretching mode is set, the engine may still consider there to be 720 pixels between the left and right of your scene. For instance, notice the field of view on your background does not change when you shrink it

rugged sequoia
#

huh

#

this is weird

#

i wanna smash my head on a board

trim scroll
#

You might have better luck using get_viewport().size which is more like the width of the game space in pixels as opposed to the OS's window size.

I wish I could explain stretch modes better to you, but I find them confusing too 😦 I typically play with them until I like how stretching the game acts

rugged sequoia
#

yeah...