JarkkoPar / Utility_AI_GDExtension

This repository contains the binaries and example project for the Utility AI GDExtension.
MIT License
72 stars 2 forks source link

Sensor range/score value not updating properly with delta #16

Closed Franz-Inc closed 8 months ago

Franz-Inc commented 8 months ago

I just wanted to report some funny behaviour (at least, funny to me) - updating a sensor range (and presumably score) value directly with delta doesn't seem to work as intended. I basically decreased an initial value of 100 from both variable and sensor.range_value and the latter hit 0 in 1.7s or so, while the former dropped 1 by 1s as expected.

func _ready():

    #for testing:
    sensor_suspicion_level.range_value = 100
    sus_level = 100
func _physics_process(delta):
    #for testing
    sensor_suspicion_level.range_value -= delta
    sus_level -= delta
    printt("Sensor:", sensor_suspicion_level.range_value)
    printt("Variable:", sus_level)

image

However, if I assign the variable to the sensor.range_value, it works fine.

func _physics_process(delta):
    #for testijng

    sus_level -= delta
    sensor_suspicion_level.range_value = sus_level
    printt("Sensor:", sensor_suspicion_level.range_value)
    printt("Variable:", sus_level)

image

Franz-Inc commented 8 months ago

After some more playing around, I think it has to do with that sensor.range_value must be an int, which I guess doesn't play nicely with delta (of course, multiplying an int every frame by a small float that is delta and having it round to a whole number will drastically change the outcome). So perhaps this is as intended - I just didn't understand the ramifications of float vs int