Hypertrails for car's tire effect (SOLVED)

Hi!

I wanted to add trails after tires using Hypertrails by @aglitchman , but when I rotate the position of the object with trail model and script that is slightly offset towards the origin of the car - one of the trails is behaving unexpectedly: (the red and blue lines are for debugging - velocity and forward/frontal direction of the car)

tire_trails-ezgif.com-optimize

You can see above, that one tire trail (left one of the car) behaves precisely, like I would like them to be, so that it’s head position is changed, but the trail is “drawn” on the track and left untouched, but the other one (right one of the car) somehow “translates” the whole trail.

If I removed them both and created again right trail game object first, and then add left game object - the behaviour is the same, but the last created one behaves wrongly.

I have trails in separate game objects:

image

And I update their position with the simple script:

local function update_trail_positions()
	local car_rotation = go.get_rotation("/car")
	local car_position = go.get_world_position("/car")

	local new_pos_left = car_position + vmath.rotate(car_rotation, TRAIL_LEFT_OFFSET)
	local new_pos_right = car_position + vmath.rotate(car_rotation, TRAIL_RIGHT_OFFSET)

	go.set_position(new_pos_left, "/trail_left")
	go.set_position(new_pos_right, "/trail_right")
end

I don’t want to make them simply child of the car object, because it causes the whole trail to rotate also:

tire_trails_child-ezgif.com-optimize
in this configuration:
image

But maybe I’m doing something wrong?


Properties of the trail scripts are identical, except I named models _left and _right:

Oh, ok, I wanted to emphasize the problem to you, so I changed color of the left trail to red :red_car: and right trail to blue :blue_car:, but it turned out both are blue!

So, I guess, changing properties of script instances in the collection are “overwriting” themselves?

Somehow I can’t change properties - changing anything in the first in Outline script is overwritten by the second one, for both instances? I don’t understand this behavior :frowning:

Tips:

  1. Use the latest version from the ‘master’ branch.
  2. Don’t attach trail game objects to any parents. Otherwise, its behavior will be hard to control because you need to recalculate offset of the trail mesh to be relative to the parent and so on . Just change trail objects position on every update from the script that controls car and it should work fine.
3 Likes

No, the properties are (supposed to be) per instance of the script.
So, if you’ve set two different colors on the scripts, start by verifying that your properties are correct in your init() function of the script, by printing them out.
Add a test property to compare with, like a number, to verify with.

go.property("test", 0)

and change it to e.g. 1 and 2 for the scripts respectively.

function init(self)
    print("init test", self.test)
end

and it should print out

init test 1
init test 2

But I also noticed that it’s the new functionality of editing vertex attributes in the editor.
Perhaps that part isn’t working fully as intended yet. :thinking:

EDIT: Another thing is to check if bundling helps (as we then run Bob for building the content)

1 Like

I have an error here (there is not faststream - is it some kind of extension?)

ERROR:SCRIPT: hyper_trails/trail_maker.lua:198: attempt to index global ‘faststream’ (a nil value)
stack traceback:
hyper_trails/trail_maker.lua:198: in function init_buffers
hyper_trails/trail_maker.script:19: in function reset_trail
hyper_trails/trail_maker.script:26: in function <hyper_trails/trail_maker.script:25>

2 Likes

It’s working, thank you! :heart:

tire_trails_working-ezgif.com-optimize

3 Likes

So just to verify, the custom vertex attributes seem to work right? :sweat_smile:

I don’t know if this is regarding the colors, but yes, it is working:

tire_trails_working_colors

Sometimes it changes transparency though, as you can notice above, but I didn’t really figured out yet why

1 Like

I assume that particles are drawn in the same predicate as trails meshes. So they sometimes set their blend func depending on z.

1 Like