Movement relative to camera, yet again

   #Here's the ball control. Beware...
    #Max speed and forward
    maxspeed=5
    vec_vel = mathutils.Vector((0,0,0))
    
    if keypressed in[up]:
        vec_vel.x = -maxspeed
    if keypressed in[down]:
        vec_vel.x = maxspeed
    if keypressed in[right]:
        vec_vel.y = maxspeed
    if keypressed in[left]:    
        vec_vel.y = -maxspeed
    
    vec_vel=vec_vel.xyz; vec_vel.z*=-1
    
    if vec_vel.magnitude:
        vec_vel=camhelper.worldOrientation * vec_vel
        vec_vel.z=0
        vec_vel.magnitude = maxspeed
        
        ball.alignAxisToVect(vec_vel)
        ball.applyTorque(vec_vel)

This is the code I have assembled. The ball rolls when key pressed, good.
Not so good is when changing direction, because, obviously the ball aligns itself with the rotation given.

The question is, how can I set up a system that updates the ball’s rotation to the rotation of the camera?
Also, using this thing Torque (that I very much like), having maxspeed capped at 5, how can I prevent the ball’s amazing increase in rotation?

All else is going great… .blend refuses to be attached, maybe the size is too “grande”…

This are multiple problems.

Anyway I think there is an angular damping parameter for physics objects (physics panel).

i not think alighAxisToVect() can be used ?

then the matrix of the camera i guess need of some transformation before to be used.

on the second point , i’m not so sure, i often make confusion with radians

anyway i prefer make thing that i know .

using the vector forward of the camera (-Z), make it flat(vec.z=0.0) and use it as +Y to build a new matrices.
then the new rotations here multiplied by this matrices.(instead of the matrix original)




    rot = Vector()
    if   key[ev.WKEY]:        rot.x = -0.5
    elif key[ev.SKEY]:        rot.x = +0.5
    if   key[ev.AKEY]:        rot.y = -0.5
    elif key[ev.DKEY]:        rot.y = +0.5
    
    if rot.magnitude:
        rot.magnitude = 10.0
        
        vec =  -sce.active_camera.worldOrientation.col[2]
        vec.z = 0.0
        vec.normalize()
        mat = vec.to_track_quat("Y", "Z").to_matrix()
        own.applyTorque(mat * rot, 0)





The ball, can have a dynamic center that does not roll, with the camera parented to it,
then, applying regular “force” will make it roll just like a ball, using 6dof link to the center,

using “SetRot” on the “center” and having your camera parented to it, will allow for it to always apply forces in sync with the camera view, because the camera is a extension of the “center” or better yet, parent a empty to the center, and use 6dof to link the camera to it, and then you can have the Z axis ((or any)) be used to zoom in and out, with a key press easily, and since it is linked to the empty, will not apply any forces to the “center”

Also, I have something for you if you want it,

Attachments

TripBallzStrobeAlpha (2).blend (1.62 MB)