Introducing myself and a mod question

Place to get help with not working mods / modding interface.
Post Reply
nicholas80
Burner Inserter
Burner Inserter
Posts: 9
Joined: Fri Nov 13, 2020 4:52 pm
Contact:

Introducing myself and a mod question

Post by nicholas80 »

Hello, hope all is well and everyone is looking forward to the weekend. I have been playing factorio for a while now and I have been looking into building a mod that intruduces a load more vehicles. I am a senior programmer and have been for 20 years so the coding is no issue for me apart from learning where to put stuff ect and I am looking forward to getting started.

Ok for my mod question, as I said I want to build a mod to introduce a load of vehicles and these vehicles will have their own set of parameters like capacity, acceleration, handelling and the last one is my question. In the car or vehicle profile I can't see any fields to do with grip ect. My thought was that I wanted the vehicles to have their own character and driving feel but I can't see how that would be achieved. I'm sure you vetrans will point me to where I need to be.

Although further looking at the documentation I am getting less convinced that a realistic (as much as a top down can be) driving experience may not be possible using the vehicle profile. If that is the case is it possible to hook into some events and get there that was.

Look forward to chatting to you and maybe even collaboration with some of you.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Re: Introducing myself and a mod question

Post by Deadlock989 »

nicholas80 wrote:
Fri Nov 13, 2020 5:01 pm
In the car or vehicle profile I can't see any fields to do with grip ect.
Cars inherit friction or friction_force from the abstract vehicle prototype if that's at all close to what you're looking for. As far as I know they are not much more than acceleration/deacceleration modifiers. https://wiki.factorio.com/Prototype/Car

Different tiles (both land and placeable tiles) can also specify vehicle friction modifiers (I think a multiplier, from memory).

I'm not sure how much of a "realistic" driving experience you are ever going to get. Stuff like drifting for example isn't part of the game engine. I don't see what events you might hook to, there are not many vehicle-specific events. You could do stuff to whatever the players are driving in on_tick or on_nth_tick but it doesn't take much with those to murder the game's performance unless you're doing something really trivial.
Image

PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: Introducing myself and a mod question

Post by PFQNiet »

You may be able to use on_tick to track a car's inertia and, if it doesn't match the current velocity (ie. the car has turned sharply enough) then you can "teleport" the car in the direction of inertia to simulate drift. You can use properties from the car's prototype to tweak how it should handle.

It's worth noting that while on_tick can be problematic for performance, in this case you'd only be working on a single entity (per player - namely, the car they are driving if any). You'd only be doing very trivial maths. Stuff this simple should be perfectly fine in on_tick without too much worry about performance.

nicholas80
Burner Inserter
Burner Inserter
Posts: 9
Joined: Fri Nov 13, 2020 4:52 pm
Contact:

Re: Introducing myself and a mod question

Post by nicholas80 »

Thanks guys. I have spent the evening trying to get a hello world mod up and running but my lad has been calling me away to help with his Jurassic Park Evo game so I have not been able to focus and I will hopefully get something running over the weekend.

I know it will never be very realistic driving physics but what I really wanted was for people to tell the difference between the vehicles. There are some variables to play with that I have found that effect the acceleration fuel consumption and turn circle which will vary things quite a bit. I do like the idea of using the on tick or on n tick events and if I keep the procedure really simple then we could get some drift going on.

From what I can see the graphics is a table of png images that are rotated for animation. If anyone has any tips and tricks to do with the sprite system I would love to hear your experiences.

nicholas80
Burner Inserter
Burner Inserter
Posts: 9
Joined: Fri Nov 13, 2020 4:52 pm
Contact:

Re: Introducing myself and a mod question

Post by nicholas80 »

I have been drawing a few things out to try and see how the inertia thing can be done cheating on a bit of the process expensive math when I noticed about collisions.

If I hit a wall with my car (I do not intend to try this) the resulting motion of the car will depend on the angle of incidence which will give an angle.of reflection and the velocity would be slowed proportional to the angle of incidence.

Using the teleport method can a vector be set also

Koub
Global Moderator
Global Moderator
Posts: 7199
Joined: Fri May 30, 2014 8:54 am
Contact:

Re: Introducing myself and a mod question

Post by Koub »

[Koub] On second thought, moving this to modding help.
Koub - Please consider English is not my native language.

PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: Introducing myself and a mod question

Post by PFQNiet »

nicholas80 wrote:
Sat Nov 14, 2020 5:35 am
Using the teleport method can a vector be set also
Yes. `teleport` accepts a position, but it also accepts two numbers that are used as a vector.

Code: Select all

entity.teleport(2,0) -- teleport 2 tiles to the right

nicholas80
Burner Inserter
Burner Inserter
Posts: 9
Joined: Fri Nov 13, 2020 4:52 pm
Contact:

Re: Introducing myself and a mod question

Post by nicholas80 »

PFQNiet wrote:
Sat Nov 14, 2020 11:27 am
nicholas80 wrote:
Sat Nov 14, 2020 5:35 am
Using the teleport method can a vector be set also
Yes. `teleport` accepts a position, but it also accepts two numbers that are used as a vector.

Code: Select all

entity.teleport(2,0) -- teleport 2 tiles to the right
So say I was moving east at 2 tiles per second can the teleport method move me to 5 tiles west of my previous position but be moving at 1 tile per second in a West direction.

Thinking about it is there any function to change the players speed and direction programmatically because if there is I may be able to do what I need to with little or no use of the teleport command.

I assume somewhere the players vector will be stored because when I let go of the acceleration key the car slows and stops. So is there a function to get the players current vector and is there a function to modify the players vector.

PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: Introducing myself and a mod question

Post by PFQNiet »

You can set the entity's speed and orientation, although last I checked changing orientation doesn't work so well for vehicles (possibly due to how they can't be rotated by the player? I don't know I gave up and went with a different solution to that problem :D). Even if it did work, the car would only move in the forward (or backward) direction so drifting wouldn't be possible with that.

Teleporting would keep your speed and direction unchanged, so if you teleport by a small amount each tick then you can indeed drift.

nicholas80
Burner Inserter
Burner Inserter
Posts: 9
Joined: Fri Nov 13, 2020 4:52 pm
Contact:

Re: Introducing myself and a mod question

Post by nicholas80 »

So for all entities their movement is tied into their orientation. That does kind of make it impossible apart from the teleport hack.

With the teleport function is the resolution in tiles because the fact a vehicle goes forward and backwards smoothly means a vehicle can be a faction inside a tile boundary.

PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: Introducing myself and a mod question

Post by PFQNiet »

Yes, teleport is measured in tiles and you can use decimal parts of a tile for entities that are "placeable-off-grid" (which vehicles are).

Post Reply

Return to “Modding help”