So, the code I’m using right now technically gets the job done, but I’m far enough into programming to know it’s not the best way of doing things, but not far enough to know why it’s not proper. Is there any better way of applying this sprint function? Any help/insight would be appreciated.
this is redundant code, you have a function that is a single if, you might as well just have the code directly in physics process.
clean up of code is very much important.
also for something like this it will make it easier to add new features.
too many variables, too many exports. find a way to simplify this code or sacrifice features. also do the math in paper and simplify the code, like using a curve and sampling it, and find the correct values and turn them into consts.
then put all the consts into an autoload so they are not in the script. exports are for setting these values per unique scene that uses the script, but the game created instances will still share it. avoid exports for speed and rotation values.
is there something that is not working? because if it’s working just leave it, unless you need new features.
Thank you for the insight, I probably don’t need just an if function as you say, and it would be better to just stick it in the physics process. The variables however are supposed to be upgradable/exchangeable through equipment later on, so I don’t know if just making them constants at this point would be a good idea. This is something I have not implemented yet as I have other priorities right now, but I fear I would be making it harder for myself later on if I make them constants now.
then don’t make export. just var is enough, change them from a different script or function.
an alternative is to create a new class “template” so you can get these values from a node that is children of the main node. or just use a function like get_max_speed that returns a float with has_method("get_max_speed").
an even better alternative is to use metadata.
put meta_data in the node, like float max_speed with a value of 170.0.
then access this node from your character using get_meta("max_speed", 170.0), where it will try to obtain the metadata max_speed, and if it’s not assign it will return 170.0.
Car (Root of scene)
\-> Basic engine (Node) with metadata max_speed = 170.0
swap the “basic engine” node with a different scene
Car
\-> V6 (Node) with metadata max_speed = 200.0
V6 and V8 are scenes consisting of a single Node with metadata.
Thank you, that really seems like the best way of going about things! I will try to update this post later on with my implementation for future reference.