ACM - Advanced Controls Mod [Besiege v0.45]

Discussion in 'Besiege: Modding' started by Lench, May 16, 2016.

  1. Lench

    Lench Active Member

    I suppose there's a way to script it, but can't give you the exact implementation from the top of my head. Not sure if I even wrote the API for the camera block. You're welcome to join us in Besiege Discord here https://discord.gg/33WPYEP and I'll see if we can figure something out.
     
  2. Steamzombie

    Steamzombie New Member

    I've been tinkering with my atan2 directional controls and added another input to allow rotation of the machine with the same steering system. I have 8 wheels in a compass layout connected to a steering block each.
    I need two custom axis, one for wheel speed [0, 1] and one for stering block angle [-1, 1] which equals [-180°; 180°]

    I use input from
    Left Y (+forwards/-backwards)
    Left X (-left/+right)
    Right X (-turn left/+ turn right)
    α (Direction the wheel needs to face in order for the machine to turn right. This variable is different for each wheel. It is the direction for the Right X vector)
    Code:
    α for each wheel
                       North wheel 1/2 pi
           NW wheel 1/4 pi    NE wheel 3/4 pi
    West wheel: 0                          East wheel pi
           SW wheel: -1/4 pi      SE wheel: -3/4 pi
                       South wheel: -1/2 pi
    
    

    Here's the maths:
    First I convert polar vector {Right X, α} into a carthesian vector {Xr, Yr}.
    Code:
    Xr=Right X*cos α
    Yr=Right X*sin α
    Then I can add that vector to the left stick's vector {Left X, Left Y} to make the resulting direction vector {X, Y}.
    Code:
    X=Left X+Xr
    Y=Left Y+Yr
    For the wheel speed {Xs, Ys}, I multiply the two vectors with 0.7 and 0.5 respectively before adding them so they are weighted torwards speed and Xs and Ys stay in the range of [0,1]
    Code:
    Xs=0.7*Left X+0.3*Xr
    Ys=0.7*Left Y+0.3*Yr
    Now I convert into polar coordinates again. For the steering block angle I use atan2. To comply with the [-1,1] range I divide by pi.
    Code:
    steering block angle = atan2(X, Y)/pi
    For the wheel speed I use pythagoras.
    Code:
    wheel speed = sqrt(Xs²+Ys²)

    So basically, the two formulas are
    Code:
    wheel speed = sqrt((0.7*Left X+0.3*Right X*cos α)²+(0.7*Left Y+0.3*Right X*sin α)²)
    steering block angle = atan2(Left X+Right X*cos α, Left Y+Right X*sin α)/pi
    with α being specific to each wheel

    here's what I got:

    init code
    Code:
    from math import *
    LeftX = AdvancedControls.GetAxis("Left X")
    LeftY = AdvancedControls.GetAxis("Left Y")
    RightX = AdvancedControls.GetAxis("Right X")
    
    update code for the wheels
    Code:
    sqrt(
    pow((
      0.7*LeftX.OutputValue+0.3*RightX.OutputValue*cos(alpha)
    ),2)
    +
    pow((
      0.7*LeftY.OutputValue+0.3*RightX.OutputValue*sin(alpha)
    ),2)
    )
    update code for the steering blocks
    Code:
    atan2(
    LeftX.OutputValue+RightX.OutputValue*cos(alpha),
    LeftY.OutputValue+RightX.OutputValue*sin(alpha)
    )/pi
    
    Edit: I didn't get the sin and cos functions to work. So in the code above I replaced them with the numeric values.
    Code:
    Wheel  cos(α)  sin(α)
    N      1       0
    NE     0.707  -0.707
    E      0      -1
    SE    -0.707  -0.707
    S     -1       0
    SW    -0.707   0.707
    W      0       1
    NW     0.707   0.707
    
    It works now, I now have a first person shooter control scheme that is somewhat stable. It is still hard to actually track targets, even after I replaced the right stick with my mouse. But it corners better than sleds and hovers because it can drift like a car whereas sleds and hovers have to be manually decelerated in the old direction and accelerated in the new one.

    Next project: Third person shooter style intelligent controls with the bot's facing trying to match the Left stick's direction and a turret that tries to match the camera's facing, because right now my car and therefore my camera gets knocked around too much by small bumps to have the camera follow the bot instead of the other way round. I really would like this control scheme to be usable in pvp, although I wonder how pvp will be regulated. Would scripting be even allowed at all?
     
    Last edited: Nov 7, 2017
  3. Sanpyr

    Sanpyr Member

    didn't even realize this was a thing :O
    cant wait to use this to control spaceships like in space engineers
     
  4. Sanpyr

    Sanpyr Member

    There seems to be a issue with mouse controls:
    so when I map a block (in this circumstance, I used a steering hinge) to mouse controls, but if my mouse is in the center of the screen in the axis it is controlled by when I click play, sometimes it doesn't really move. it will wriggle a few degrees sometimes, and sometimes it will unstick itself, but it doesn't really move, there isn't any console errors either. otherwise, the mod is amazing, thanks! :)

    EDIT: the problem seems to be in the Angle option, if I bind a steering hinge to input or rotation speed it works fine
     
    Last edited: Nov 15, 2017
  5. Mxdanger

    Mxdanger New Member

    I gotta little itch to scratch. The downloads link for Macs shows OSX when it's now called macOS. ;)
     

Share This Page