angle comparison, velocity and stuff

This forum is currently in read-only mode.
From the Asset Store
Screen Comparison
$1.60 USD
60% off
See how your Logical Resolution looks on different devices
  • hi again!

    been a long while since i last booted up construct, my very own ministudio has kept me too busy. anyway, i decided to take a long break from recording and producing and dig into construct again. i got a great vision of making a sort of, violent, arcadey, top down, permadeath-ish, weird ice hockey, beat em up hybrid. (yes, thats right)

    i started slowly exploring possibilities and decided to first and foremost nail a convincing looking skating system with a small sense of inertia(?) and weight. physics behav is pretty much the way to go, but my issues are surprisingly more cosmetic, yet important,since i want to give myself some kind of vision, inspiration and motivation to keep going:

    1) comparing turning direction:

    what would be the best way to compare turning direction? i want to have a different, proper circling skating animation,when turning(both left or right), with anim(speed) connected to velocity AND with a little treshold, meaning that you dont have to go absolutely straight to switch to basic, non turning skating animation. in short, i would need to have some leeway before circling skate animation is triggered.

    does anyone have any good ideas?

    2) animation frame from 4 to 9 is playing (for example):

    how can i compare animation frames between certain values?

    the reason i need this, is that ive set up a sort of ice decal,pasted onto canvas when the character "kicks" the ice (that only happens during certain frames in the animation).

    and last

    3) detecting when the player adds force to an opposite direction of the curent velocity (again, with some kind of treshold):

    i would need this to make full sudden stops. i really cant use keyboard control presses with this, since im using physics and the movement angles are not absolute.

    basic idea is that if the player goes right and presses left(adding force to left), i would like the player to brake with more strength and change the direction when stopped (instead of starting a circling motion to turn as it is now). this would be rather easy with simple key press comparisons, but i have to take note of the velocity and angles between the basic directions. so it would be better if the comparison was made with the objects velocity in mind.

    thats all for now. im sure ill have a lot more issues with this in the future. im still trying my best to keep this simple, but you never know what ideas spring to mind. this proper skating system is my top priority as of now, though.

    the year is about to change so im sure you all are busy and stuff,so no need to scratch your head right away if you dont want to. i could try and post a simple .cap to illustrate my issues better later.

    EDIT: threw this together with a quick anim rip i made lol. theres also anims for circling skate animation if someone knows how to implement them:

    http://dl.dropbox.com/u/11157144/hockey-proto.cap

    anyway, thanks for advance and HAPPY NEW YEAR everyone!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • so i tried to get that angle/lastangle thing for the circle skating to work, i found some old thread about sort of similar issue here:

    http://www.scirra.com/forum/how-would-you-is-turning_topic41426.html

    tried to implement the code given there to my own purposes, but i still cant seem to get it right. first of all, the animation does not work. the turning skating animation shows a proper angle(though it randomly starts switching direction rapidly), but it doesnt play the animation, just the first frame. im not sure what the problem is. another thing: i tried to test and see if i could point out whats wrong with it. i put a text showing the angle difference between player sprite and variable "lastangle" BUT it only shows me the angle difference between 0(angle) and var. "lastangle" ?? <img src="smileys/smiley24.gif" border="0" align="middle">

    so, it doesnt update the player's angle at all, but assumes its always 0? do i need some additional maths to calculate the players current angle? or maybe i just dont know how to use anglediff properly.

    anyway heres the updated .cap to help understand my frustration:

    (sorry its kind of a little mess)

    http://dl.dropbox.com/u/11157144/hockey-concept.cap

    so, any advice or help would be really appreciated <img src="smileys/smiley41.gif" border="0" align="middle">

  • I'm not trying to be a jerk but.

    Pro Tip:

    The people on this site are more than happy to help with problems. however most people are not willing to read a wall of text. you'll probably get more help from more people if you simplify your problem. and try to tackle one issue at a time.

    heck maybe that will help you figure it out yourself. the key to understanding anything is asking the right questions.

    __________________________________________________________

    I Took a quick look at what you got going on, but I'm not sure were to begin or what exactly you want.

    I think you should look at how your events are ordered, just by moving your second "Always:" event above your first "Always:" event I got certain animations to work.

    and if you use set sprite3.angle to angle(0,0,Sprite2[Physics].VelocityX,Sprite2[Physics].VelocityY)

    you don't have to use 2 unnecessary variables to keep track of your last position. just to find your current animation angle.

    Also I highly recommend reading this blog post on linear algebra just to help open up different methods of solving these kind of problems.

    And book mark it. I use it all the time.

    Linear algebra for game developers ~ part 1

  • hi and thanks for replying!

    and yeah i know i have a habit of blabbering with my posts lol

    i guess its partly just a habit and i also want to be as thorough about what im getting at. also english is not my first language, so im not always sure whats the simplest way of forming understandable sentences, epecially concerning coding and all this "technical" stuff.

    but anyway, the simplest way of making this question i cant get rid of:

    how to detect rotation speed?

    for example:

    -sprite rotates clockwise slower than 5 degrees ,say, every 100 milliseconds.

    --->play animation 1

    -sprite rotates clockwise faster than 5 degrees ,say, every 100 milliseconds.

    --->play animation 2

    and of course, same for the counter clockwise. (which would be animation 3. animation 1 would be in this case skating straight)

    tried to keep it as short as i could <img src="smileys/smiley36.gif" border="0" align="middle" />

    anyway, thanks for that piece of code. could always use less private variables, so its useful.

  • Ok thats a lot better.

    <img src="smileys/smiley2.gif" border="0" align="middle">

    here ya go:

    FIXED.cap

    ______________________________________________________________

    your logic on finding the angle speed was fine, its just that your debug Text2 object was checking "lastangle" not sprite3.('lastangle') and so was returning 0

    Just a simple oversight. otherwise you would have noticed (AngDif>5) was way to high a speed. so I changed it too (AngDif>1)

    --------------------------

    You had conflicts in finding your lastangle because you were seting it after you already changed the angle.

    That's why moving the 2nd [Always]event above the 1st[Always]event fixes that.

    -------------------------

    I also added a new vareable ('speed') witch I used to determin the idle/skate animations.

    Its just: sqrt(a^2+b^2)

    so

    ('speed') = sqrt(Sprite2[Physics].VelocityX^2+Sprite2[Physics].Velocityy^2)

    --------------------------

    fixed your events that set value 1/2 to find left/right, (you had 1/right, to find left/2)

    and added a [Trigger Once] to your input key animation change event.

    ___________________________________________________________

    TIPS:

    1.Never name a variable "angle". It just makes things confusing. so I changed that to "ang"

    2. Never use large canvas objects. they kill FPS. your better off with hundreds of sprites.

    ______________________________________________________________

    ha,no wonder you were having a hard time explaining, there was nothing majorly wrong, just a whole bunch of small oversights and errors.

    you still should keep a bookmark on the blog I linked though.

    I have a feeling your going to need it to make vectors to find torqe and swing angles in the future.

    <img src="smileys/smiley1.gif" border="0" align="middle">

  • needless to say that im quite embarrassed <img src="smileys/smiley9.gif" border="0" align="middle" />

    that lastangle thing was just one big brainfart lol. caused alot of harm though.

    even more embarrassing was that i spent last evening trying to get the circling animations to work, cause they didnt. i stared at my events list, trying to figure out whats wrong. asked myself what is wrong with those frames not playing properly.

    FRAMES.

    then it hit me. it was the event that determined how fast FRAMES were playing compared to speed,causing conflict when there wasnt enough frames in the circling animations, or atleast something like that. <img src="smileys/smiley36.gif" border="0" align="middle" />

    so simple, yet completely invisible to me.

    so yeah, you were right, sometimes its better to ask yourself what is wrong. although i would probably be still scratching my head if you didnt help me so, big thanks and gratitude.

    i made a note list a long time ago to give myself hints from past errors and there was "name your problem and search that name(or something related) from the event list to troubleshoot."

    that hint would have been a great help in this case, had i checked that note list lol.

    well i guess i move on to next problems to try and see if i can make something out of them. and yeah, i bookmarked that page you sent, could be really useful.

    anyway, appreciated!

  • happy to help.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)