Smooth Character turning / Natürlich Charakterdrehung

  • #20, z MachtnixTuesday, 23. September 2014, 23:50 hodinky 10 years ago
    Now it TURNS to off-topic,.... *lol*

    Kapitán

    1097 Posts


  • #21, z afrlmeWednesday, 24. September 2014, 00:11 hodinky 10 years ago
    Bleh! I've always been a fan of off-topic threads, they make forums more interesting. I encouraged them on my own forums, unlike some forums where you have some wanker getting out the off-topic red card.

    Imperátor

    7285 Posts

  • #22, z MachtnixWednesday, 24. September 2014, 00:56 hodinky 10 years ago
    I've always been a fan of off-topic threads


    Me too. I don't want to be a "Spielverderber" (spoil-sport??).

    Kapitán

    1097 Posts

  • #23, z AlexMonday, 29. September 2014, 12:58 hodinky 10 years ago
    I planned to add a character turning option but couldn't implement it so far. First it turned out to be way more difficult than I thought. Initially I only planned turning while walking (so I could add it to an existing event handler), but the character must also turn if it is aligned either by action part or because an action is executed on an object - probably an own state (besides walking, standing, talking) and a lot of internal handling is needed. Further I didn't have as much time as I thought (due to work, personal stuff etc.). I'll give it another try next month.

    btw, I haven't followed the end of this thread (seems to be a little off-topic wink)

    Čestný člen

    378 Posts

  • #24, z afrlmeMonday, 29. September 2014, 13:41 hodinky 10 years ago
    btw, I haven't followed the end of this thread (seems to be a little off-topic wink)


    And? grin (just means the threads, that little bit more interesting).

    I said in this thread that it would be complicated because you have to get current alignment vs destination alignment (alignment character will face before setting off), as well as determine which is best way for character to rotate (clockwise or anti-clockwise) & finally you have to check if destination has an execution action/command/item drop etc & if so you then need to create a table or something to store these actions into & a state so that it knows what type of action it was so that it can correctly retrieve & resume the actions on walk.

    During walking is also complicated as I mentioned because you need to determine if character should stop & turn or keep moving while turning (maybe at 1/3 of current speed) while making sure the frames are correct while cycling through the different directions.

    Anyway... Good luck with writing the function/action part/hook Alex mate, I think it would be appreciated by quite a lot of the members (& future members) on here. wink

    Imperátor

    7285 Posts

  • #25, z vectracocoTuesday, 30. September 2014, 10:45 hodinky 10 years ago
    Alex! AFRlme! If you add the option to turn of character you will become the best software for existing adventure games Visionaire is today. There is no reason to choose another.
    It seems silly, but I know a lot of people hating the sharp turn of the character.
    Also I think that it is not as complicated as it seems.
    I don't have much time, but when I can I prepare an outline of the way in which you can make. Maybe it can be useful.

    I hope that me you understand, my English is not the best in the world. I am sorry.

    Bažant

    19 Posts

  • #26, z vectracocoTuesday, 30. September 2014, 11:02 hodinky 10 years ago
    https://www.youtube.com/watch?v=bGbwqp1JtMA

    You can watch the attached video at minute 3:38.
    I think that you don't have to complicate both to achieve a good effect.
    Really smooth rotation is achieved by adding 2 frames (no need more)
    with the feet always on the ground quickly.
    I have found that it is the most effective way of doing so.
    Sorry if I get result on your things but I take much time as animator of characters. I only intend to help a little.
    Thank you for your great work.

    Bažant

    19 Posts

  • #27, z afrlmeTuesday, 30. September 2014, 12:26 hodinky 10 years ago
    This is rotate on stop. Plus it's pixel art. I guess there are multiple ways to animate that...

    Yesterday I remembered that the fan made Broken Sword .5 had a nice walking & rotation system & that their engine which utilizes scummvm was shared as open source on github. I had a little look through their code pages but haven't seen how they achieved character rotation, amongst other things as I figured it might be a nice place for the vs devs to base their own character turn system on.

    I didn't really care for Broken Sword 2.5 very much as the voice acting irritated me to no end, but the walk system was really good.

    P.S: I'm not a vs dev, I just provide support for you lot on here & the wiki, think up ideas & create lua scripts & functions (most of which I share).

    Imperátor

    7285 Posts

  • #28, z SimonSTuesday, 30. September 2014, 13:23 hodinky 10 years ago
    I tested some, seems it could be done with lua already. The script isn't finished there is always some wrong turning and such, it's just a demonstration, and maybe a hint for someone who has more time for these scripts. I created an animation "character_turn" for the current character with a 360 degree. Then I put all directions of that animation into a table smt_animation. It currently breaks a lot of things such as a double click on an exit.
    -- Smooth Character Turning Test/Demonstation Script 
    -- (c) Simon Scheckel 2014 - Visionaire Studio Engine
    
    smt_animation = {Rufus = {135, 150, 180, 225, 270, 315, 0, 25, 45, 90, 110}}
    smt_direction = game.CurrentCharacter.Direction
    smt_state = game.CurrentCharacter.AnimState
    smt_dest = game.CurrentCharacter.Position
    smt_destobj = game.CurrentCharacter.DestinationObject
    smt_actionc = game.CurrentCharacter.ActionCharacter
    smt_anim = 0
    
    function angleDist(a,b)
    	return math.min(math.min( math.abs(a + 360 - b), math.abs(a - 360 - b)), math.abs(a - b))
    end
    
    function smoothTurningMainLoop()
    	local newstate = game.CurrentCharacter.AnimState
    	local newdir = game.CurrentCharacter.Direction
    	local c = game.CurrentCharacter
    	local animTable = smt_animation[c:getName()]
    	if smt_anim ~= 0 and smt_anim:getId().id==-1 then
    		smt_anim = 0
    		c.DestinationObject = smt_destobj
    		c.ActionCharacter = smt_actionc
    		--c.Position = {x=smt_dest.x-1,y=smt_dest.y-1}
    		c.Destination = smt_dest
    	end
    	if smt_direction~=newdir then
    		local turn = false
    		if newstate == eWalkAnim and smt_state ~= eWalkAnim then
    			smt_dest = c.Destination
    			smt_destobj = c.DestinationObject
    			smt_actionc = c.ActionCharacter
    			c.Destination = c.Position
    			turn = true
    		end
    		if newstate ~= eWalkAnim and smt_state == eWalkAnim then
    			turn = true
    		end
    		if turn then
    			smt_anim = startAnimation(getObject("Game.GameCurrentCharacter.CharacterCurrentOutfit.OutfitCharacterAnimations[character_turn]"))
    			local bestspos = 1
    			local bestdist = 360
    			for i = 1, #animTable do
    				local dist = angleDist(animTable[i], smt_direction)
    				if  dist < bestdist then
    					bestdist = dist
    					bestpos = i
    				end
    			end
    			local bestlpos = 1
    			bestdist = 360
    			for i = 1, #animTable do
    				local dist = angleDist(animTable[i], newdir)
    				if  dist < bestdist then
    					bestdist = dist
    					bestlpos = i
    				end
    			end
    			print(bestspos.." "..bestlpos)
    			smt_anim.AnimationFirstFrame = bestspos
    			smt_anim.AnimationLastFrame = bestlpos
    			smt_anim.PlayOppositeDirection = bestspos > bestlpos
    			if bestspos > bestlpos then
    				smt_anim.AnimationFirstFrame = bestlpos
    				smt_anim.AnimationLastFrame = bestspos
    			end
    		end
    	end
    	smt_direction = newdir
    	smt_state = newstarte
    end
    registerEventHandler("mainLoop", "smoothTurningMainLoop")
    

    Kapitán

    1582 Posts

  • #29, z Lord7evenTuesday, 30. September 2014, 13:44 hodinky 10 years ago
    Thanks for all your updates, ideas and inputs. With the 3d models I mentioned earlier I just wanted to say, if you can import 3d models, you should be able to turn them as well. I didn't use 3d models yet so I have no idea how they work but I think they're a bit different than standard 2d pictures for characters. (Maybe I'm wrong.)

    EDIT: Just saw the script, I'll test that later. Thank you for your work!

    Bažant

    40 Posts

  • #30, z vectracocoTuesday, 30. September 2014, 14:00 hodinky 10 years ago
    I just had thought something simple to somewhat soften the sharp turn of the character in standing as well said AFRlme. But it seems that there are good ideas and desire to achieve perfection.
    Welcome are ideas. Good job Simons.

    Bažant

    19 Posts