Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Tato64 |
Hey gang! Im here once again finding new ways to lose my mind
Basically, top-down 2D, im trying to implement skid marks for when cars drift.
The marks will start when the car is drifting, will add line2D points while it’s drifting, and stop adding point when it stops drifting. (Afterwards the line2D will fade out and delete itself)
To be clear, this https://www.youtube.com/watch?v=s5DwZZ0fZDg is NOT what im trying to do. (trails that follow the wheels all the time), i want trails that will appear when triggered, stop when triggered to stop, stay there in the world for a while and then dissapear.
Believe me i have tried a lot of methods but none worked like i want to.
My relevant code is the following, it seems to correctly manage the “Start, drift, end”, but doesnt work at all since no Line2D shows, im adding it in case its worthy to “fix”:
(This is in _physics_process)
var drifting = false
var driftmark1 = driftmark.instance()
if Input.is_action_just_pressed("space"): #The first press of space starts the drift.
print("drift start") #Debugging purposes
get_parent().add_child(driftmark1) #Adds the "driftmark" node to the world.
driftmark1.set_global_position($Wheelpos.global_position) #In the position of the wheel
drifting = true #Its drifting
if Input.is_action_just_released("ui_select"): #When space is released
print("drift end") #Debugging purposes
drifting = false #It's not drifting
if Input.is_action_pressed("ui_select"): #WHILE space is held down
print("adding point")
if drifting:
driftmark1.add_point($Wheelpos.global_position) #Adds points to the Line2D in the wheel position
(The “Fading out and deleting itself” part is managed in the driftmark node itself. It’s just a timer that fades everything out, and then another timer that queue_free’s the node)
Thanks in advance for any help!
A few comments / questions:
First, I notice you’re using both a “space” action and a “ui_select” action. I assume both are wired to the space bar, right? Since you say the code seems to correctly manage start, drift, and end, I assume so…
Once you’ve added (or think you’ve added a drift mark) in-game, you should be able to inspect the live scene tree and see what your line looks like.
Just run your game, add some drift points (but don’t delete them for now), open the Remote scene tree, navigate to the Line2D
node that represents your drift mark and see what it looks like.
- Does it exist?
- Is it where (in space) you expect it to be?
- Does it have any points associated with it?
- Are the points as expected?
jgodfrey | 2020-12-11 22:58
Hey!
First of all, thanks for helping out.
And yes, “space” and “ui_select” are the same, thanks for pointing that out, didnt notice.
Second, after launching the sandbox scene and drifting a bit, the “driftmark” nodes show up correctly on the “remote” list (I drifted 4 times, i have 4 instances of it) and delete themselves after some time like intended.
After that, i added a “print” for get_point_count()
to see if they’re being added. Only 1 point is being added.
This surely seems to be the culprit.
I’m looking into it but let me know if you figure something out
Tato64 | 2020-12-11 23:37
Hmmm, what seems weird to me is that:
if Input.is_action_pressed("ui_select"):
print("adding point")
if drifting:
driftmark1.add_point($Wheelpos.global_position)
This prints an “Adding point” every frame. But it doesnt add a point every frame, it only adds one. (I tried removing the “If drifting” condition but it did nothing.
EDIT: Ok, i added print("adding point")
to the “if drifting” and it triggers only once, so that var should be removed altogether.
EDIT 2: OMG IT WAS SO HARD TO FIGURE OUT BUT I COULD DO IT, THANK YOU SO MUCH FOR MAKING ME SEE WHERE THE ACTUAL PROBLEM WAS., i’ll update with a detailed answer right now
Tato64 | 2020-12-11 23:48