26

(20 replies, posted in Scripting)

Thanks! com3D it works!. big_smile Now i just need to found out why it only works when used only on one direction tongue, when i use the same code on the other directions they all play fast again even the walk forward, maybe i need to separate them on individual functions (for example walk forward function a walk backward function, etc) instead of being all inside one function and separated by if statements?

edit: Separated the movements on different functions didn't worked. sad

At lest i was able to change the character Run function to be able to change the walk sound timing, now when i press shift and the character runs the sounds play faster like he is really running. big_smile

I DID IT! Sorry for the caps but i'm happy. big_smile

It was just a matter of using "elseif" for the rest of the directions and only put the "else isPlaying = false end" at the end of the "elseif" statements worked like a charm. big_smile

Thanks guys for all the help.

27

(20 replies, posted in Scripting)

Thanks man for all your time, your work was not wasted, right now i comprehend more than what i did when trying this for the first time. smile

The answer will come one day, i will continue trying with this because i also liked LUA it indeed seams to be a much easier programing language then C# that i was trying to learn.

28

(20 replies, posted in Scripting)

Has i said i'm not a coder so i can't really resolve this problem but from the the little i know maybe this page on the wiki will help coroutines?

29

(20 replies, posted in Scripting)

Thanks Tutorial Doctor!! You are awesome. 

And thanks to you to com3D, for explaining that bit of code and helping TD, and yes i checked the Wiki before posting but didn't saw anything there that could help me, as i said i'm not really a coder, i'm a 3D modeler and i just like to dabble a little with code, but nothing very complex because as you saw i get stuck very easily, but i don't really have the habit of asking people for help, i try to find the answer myself by looking on the net. 

edit: Hum i used the code above and the sounds still play all very fast and on top of eachother, Tutorial Doctor are you sure it works well on your end?
Maybe some kind of timer will be needed to control the sounds timing just like on the Unity3D code.

30

(20 replies, posted in Scripting)

thanks man for taking the time to help me i really appreciate  it,  but unfortunately that code is not what i really want, on the full code i posted above you can see i already use something similar for the jump sound, now what i want is playing random foot steep sounds has the player walks, and i want a particular sound (audio length)  to wait for the other to stop playing before starting, i did something similar on Unity3D using arrays and someaudio.length plus waitForSeconds(someaudio) and it works very well. The problem i don't know how to convert the unity script code (not made by me btw) to a LUA counterpart or if maratis even has a audio length option.

Here is the Unity code just for example

var walkSounds : AudioClip[];
var audioStepLength = 0.3;


function Awake () {
    
    PlayStepSounds();
}

function PlayStepSounds () {
    var controller : CharacterController = GetComponent(CharacterController);

    while (true) {
        if (controller.isGrounded && controller.velocity.magnitude > 0.3) {
            audio.clip = walkSounds[Random.Range(0, walkSounds.length)];
            audio.Play();
            yield WaitForSeconds(audioStepLength);
        } else {
            yield;
        }
    }
}

31

(20 replies, posted in Scripting)

Hey thanks for the reply, i'm not really a coder so i don´t know what (#walkSound) does i just know that if i remove the # from it the sounds stop playing. About making the function before calling it, i did that, i forgot to put a "end" on the code above but on the real code it is there, so the playsteepsounds() function is outside the onSceneUpdate() function.

below is the full code

-----------------------------------------------------------------------------------
-- Maratis
-- Jules script test
-----------------------------------------------------------------------------------

-- get objects
Player = getObject("Player")
Head = getObject("Head")

dx = 0.0
dy = 0.0

-- walk var
walkSound = {} -- array
walkSound[1] = getObject("walk1")
walkSound[2] = getObject("walk2")
walkSound[3] = getObject("walk3")
soundLenght = 0.3

walkSpeed = 3.0


-- jump code
playMass = getMass(Player)
jumpSpeed = playMass * 50.0

Sound0 = getObject("JumpSound")
soundplay = 0


-- Run vars
runSpeed = 4.0


centerCursor()
mx = getAxis("MOUSE_X")
my = getAxis("MOUSE_Y")

-- scene update
function onSceneUpdate()

    setGravity({0,0,-2})

    coll = getNumCollisions(Player) -- for the jump code

    -- rotate Player (X mouse)
    rotate(Player, {0, 0, -1}, dx*100)
    
    -- rotate Head (Y mouse)
    rotate(Head, {-1, 0, 0}, dy*100, "local")    
    rotation = getRotation(Head)
    if rotation[1] > 90 then
        rotation[1] = 90
    elseif rotation[1] < -90 then
        rotation[1] = -90
    end

    setRotation(Head, rotation)
    
    -- move
    if isKeyPressed("W") then
        addCentralForce(Player, {0, walkSpeed, 0}, "local")
        playsteepsounds()
    end
    
    if isKeyPressed("S") then
        addCentralForce(Player, {0, -walkSpeed, 0}, "local")
    end
    
    if isKeyPressed("A") then
        addCentralForce(Player, {-3, 0, 0}, "local")
    end

    if isKeyPressed("D") then
        addCentralForce(Player, {3, 0, 0}, "local")
    end    
    
    -- run
    if isKeyPressed("W") and isKeyPressed("LSHIFT") then
        addCentralForce(Player, {0, runSpeed, 0}, "local")
    end
    
    -- jump
    if isKeyPressed("SPACE") then
        if (coll >= 1) then
            playmysound()
            addCentralForce(Player, {0, 0, jumpSpeed}, "local")
            print ("I jumped!!")
            else
                stopmysound()
            end
    end
    
    -- get mouse direction
    dx = getAxis("MOUSE_X") - mx
    dy = getAxis("MOUSE_Y") - my

    -- center cursor
    centerCursor()
    
    mx = getAxis("MOUSE_X")
    my = getAxis("MOUSE_Y")    
    
end

function playmysound()
       if soundplay == 0 then playSound(Sound0) end
       soundplay = 1
   end
   
function stopmysound()
       soundplay = 0
   end
   
 function playsteepsounds()
        characterSounds = math.random(#walkSound)
        playSound(walkSound[characterSounds])
    end

Also i got the array code idea from here http://forums.coronalabs.com/topic/3558 … ncomplete/

32

(20 replies, posted in Scripting)

Hello guys i found this nice engine and decide to play with it, the first thing i did was modify the FPS Sponza demo character controller to be able to run and jump, i'm a total noob on LUA and coding but coping code from other places and even seeing how other people is using LUA i was able to do almost what i wanted, but i'm now at a roadblock with sound.

what i want is to simulate player walk sounds, so i used a Array to do that, but the sounds are playing very fast and on top of each other, how can why solve this?

This is my array code

walkSound = {} -- array
walkSound[1] = getObject("walk1")
walkSound[2] = getObject("walk2")
walkSound[3] = getObject("walk3")

function onSceneUpdate()

-- move
    if isKeyPressed("W") then
        addCentralForce(Player, {0, walkSpeed, 0}, "local")
        playsteepsounds()
    end

function playsteepsounds()
        characterSounds = math.random(#walkSound)
        playSound(walkSound[characterSounds])
    end