# How can I let the User draw a curve in BGE while playing?

How can I make a Python code or mix python with blender things to make the user draw a track(will be a ball rolling over it) by leaving spacebar or click pressed to decide how will the track looks. maybe creating a curve and making any object, like box attach to it

Note: I want it to be made in 2D.

later I could make something, I achieve to let the User press spacebar and while he moves the mouse it puts little cylinders that make kind a path thing, but they are so far one from each other, so is not exactly what I want...

• Not sure if this is possible without some serious scripting, if at all. Anyway this is a pretty broad question as it stands. Have you tried anything so far, what have you got? May 25, 2017 at 12:51
• My answer might help you. May 25, 2017 at 21:57
• @DuarteFarrajotaRamos thanks for your answer, I hope someone solve this, I have search a lot and nothing exactly of what I want, like the thing showed I liked it, but can I put physics to that? can I make the ball crush with that? If I can, then is what I want. Anyway, I got something, I mixed the thing is shown here and some little knowledge to put cylinders when I let Spacebar pressed, but they are so distant one from each other... I want my path to be continuous. May 26, 2017 at 2:44
• @David thanks, but I guess it's not what I want... as I said before, if I can make the ball cruch with that like any mesh object, it is what I want, but otherwise is not. But thanks, I like so much that Answer, maybe usefull later. May 26, 2017 at 2:46
• Another method is to deform a mesh along the trail the mouse makes, but this is quite processor intensive if you want physics to be updated while drawing. If you're fine with the graphics being correct, but the physics being "no collision" until the end, then a deformation method could work quite well. I'll give it a shot this evening. May 26, 2017 at 9:50

# Trail Object

This object represents a single step on the trail. The x-dimension should be exactly 1.0. Make it "no collision" in physics tab to avoid interaction with other objects.

To appear as a line use plan that gets scaled to 0 on the y-axis. Give it a material with wire frame to make it visible with exactly one pixel width. It should reside on an hidden layer (otherwise add object will not work).

# Trailed object

Is the object that should leave a trail. Typically you add one trail per step. Then align the trail to the last position of the trailed object and change the size that it completely fills the step.

The script can be like that:

import bge

INTERNAL_PROPERTY_LAST_POSITION = "_last.position"

AXIS_X = 0

controller = bge.logic.getCurrentController()

owner = controller.owner

lastPosition = owner.get(INTERNAL_PROPERTY_LAST_POSITION)
currentPosition = owner.worldPosition.copy()
owner[INTERNAL_PROPERTY_LAST_POSITION] = currentPosition

if lastPosition is not None:
direction = lastPosition - currentPosition
for actuator in controller.actuators: