+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Help with applyTorque

  1. #1
    Wire Noob AndyDLP's Avatar
    Join Date
    Jun 2009
    Posts
    23

    Red face Help with applyTorque

    Hi,

    I am trying to build a car / buggy at the moment and I would like to do it without thrusters, or wheels because they tend to sink. So I was looking around the E2 Wiki and I saw applyTorque, I read the description and did'nt really understand what it meant so I tried to use it and this is what I came up with:

    Code:
    @name applyTorque Test
    @inputs Forwards Backwards Wheel:entity Plate:entity
    @outputs 
    @persist 
    @trigger all
    
    W = Wheel
    P = Plate
    
    V = W:forward()
    
    if (Forwards) {applyTorque(V)}
    This doesnt work at all, it gives me the error "No such function: applyTorque(Vector)", and yes I have updated wire and restarted gmod.

    Can anyone help me get the hang of this?

    P.S. My setup is this:

    1 PHX plate with elastic/rope suspension & the offroad prop wheel from PHX axis'd to the centre. If there is anything else ive missed feel free to point it out
    Last edited by AndyDLP; 07-21-2009 at 03:49 AM.

  2. #2
    Wire Sofaking Fizyk's Avatar
    Join Date
    Jun 2008
    Location
    Łomianki, Poland
    Posts
    740
    Blog Entries
    1

    Default Re: Help with applyTorque

    First, it's E:applyTorque(V), which means, that you need some entity to apply torque to. For example, entity():applyTorque(V), or in your case W:applyTorque(V).

    Second, torque vector's direction means the axis, about which the entity will be rotated. So if you want your car to go forward, you would want your wheels to rotate about left-right axis (assuming the wheel symmetry axis is left-right), so V should be either vec(0,1,0) or vec(0,-1,0) (applyTorque uses local coordinates).

    Which one you should use depends on the direction that you want the wheels to rotate. To go forward, you would want W:applyTorque(vec(0,1,0)). Also, you might want to multiply vec(0,1,0) by some number or W:inertia() to apply more torque, because onl vec(0,1,0) might be too weak to move your car.

    My programs: BIOS - Alcyone - Calculator - Notepad - Movie Player
    My tutorials: applyTorque - Quaternions - PID controllers
    Some other things I made: FT Chip - RK4 Solar System

  3. #3
    Wire Noob AndyDLP's Avatar
    Join Date
    Jun 2009
    Posts
    23

    Default Re: Help with applyTorque

    Ok thanks for clearing that up for me :-) now ill go see if I can get it to work
    thanks again :P

  4. #4
    Wire Sofaking nescalona's Avatar
    Join Date
    Apr 2007
    Location
    Shoreline, Washington
    Posts
    1,299

    Default Re: Help with applyTorque

    This raises a good question: for consistency with applyForce(V) and applyOffsetForce(V,V), shouldn't we create applyTorque(V) and applyAngForce(A) functions, which always act on entity()? Or would it be better to leave these out, since applyForce(V) and applyOffsetForce(V,V) are redundant and arguably shouldn't have been there in the first place?

    Also, B:applyTorque(V) is missing.

  5. #5
    Wire Noob AndyDLP's Avatar
    Join Date
    Jun 2009
    Posts
    23

    Default Re: Help with applyTorque

    Awesome it works fine now thanks :P

    BTW here is my current test code if you want to pick holes in it ^^

    Code:
    @name DuneBuggyTorque
    @inputs W:entity Move
    @outputs 
    @persist 
    @trigger all
    
    interval(100)
    
    if (Move == 1) {
    W:applyTorque(vec(0,1,0)*W:inertia()+150000)
    }
    
    if (Move == -1) {
    W:applyTorque(vec(0,-1,0)*W:inertia()-150000)
    }
    Ok so this works fine but I have one small problem, my car goes about 20 MPH, if I increase the number that I + / - then it totally spazzes and jumps in the air and make my car flip. I would rather not use thrusters but does anyone know of another way to manipulate this to make it go faster? (20 MPH sucks :P )
    Last edited by AndyDLP; 07-21-2009 at 04:51 AM.

  6. #6
    Expressionism 2.0 Syranide's Avatar
    Join Date
    Mar 2007
    Location
    Sweden
    Posts
    4,573

    Default Re: Help with applyTorque

    Quote Originally Posted by nescalona View Post
    This raises a good question: for consistency with applyForce(V) and applyOffsetForce(V,V), shouldn't we create applyTorque(V) and applyAngForce(A) functions, which always act on entity()? Or would it be better to leave these out, since applyForce(V) and applyOffsetForce(V,V) are redundant and arguably shouldn't have been there in the first place?

    Also, B:applyTorque(V) is missing.
    I'd say the bold, shouldn't have been there in the first place.

  7. #7
    Wire Sofaking Fizyk's Avatar
    Join Date
    Jun 2008
    Location
    Łomianki, Poland
    Posts
    740
    Blog Entries
    1

    Default Re: Help with applyTorque

    Multiply it by a number instead of adding a number, like:
    W:applyTorque(vec(0,1,0)*W:inertia()*100)
    To be honest, I'm surprised that adding a number to a vector didn't throw an error.

    My programs: BIOS - Alcyone - Calculator - Notepad - Movie Player
    My tutorials: applyTorque - Quaternions - PID controllers
    Some other things I made: FT Chip - RK4 Solar System

  8. #8
    Wire Noob AndyDLP's Avatar
    Join Date
    Jun 2009
    Posts
    23

    Default Re: Help with applyTorque

    When I multiply the vector it just does nothing or completely spazzes out and jumps in the air, thats why I used + & -
    Is that an error in the lua or something?

  9. #9
    Wire Sofaking Fizyk's Avatar
    Join Date
    Jun 2008
    Location
    Łomianki, Poland
    Posts
    740
    Blog Entries
    1

    Default Re: Help with applyTorque

    You are probably trying to rotate it about a wrong axis. Try changing vec(0,1,0) to vec(1,0,0) and vec(0,0,1), one of these should work. And don't add, multiply Adding is wrong.

    My programs: BIOS - Alcyone - Calculator - Notepad - Movie Player
    My tutorials: applyTorque - Quaternions - PID controllers
    Some other things I made: FT Chip - RK4 Solar System

  10. #10
    Wire Noob AndyDLP's Avatar
    Join Date
    Jun 2009
    Posts
    23

    Default Re: Help with applyTorque

    ok thanks a lot :P

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. applyTorque Tutorial
    By Fizyk in forum Expression 2 Discussion & Help
    Replies: 75
    Last Post: 2 Weeks Ago, 03:12 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots