Normal angle of a sprite at different positions

This forum is currently in read-only mode.
0 favourites
From the Asset Store
Adjusting the game screen for different resolutions (Letterbox scale)
  • What's the best way of going about finding a normal angle to an edge of a sprite.

    basically the angle of the green arrows in this picture at each of the points:

    <img src="http://www.quotecats.com/what/normalz.PNG">

    I can't think of a way that will do it at all accurately, efficiently or nicely. I need it to force an object out of a wall at the correct angle. Also this (surely) is needed for ball bounces and things (reversing the component of velocity in that direction).

  • well, in the good ol days of TGF i used to use detectors at the bottom corners of a sprite then if lets say the bottom left corner is touching and everything else isnt rotate the sprite right till the other bottom detector would touch something. then knowing the value of its rotation i.e (94 degrees) u can find the surface nromal at that location of the surface. you must also not that in order to find normals you need vector graphics, raster graphics have no information on there faces vertexes and edges are non existant, they are just pixel or no pixel (bitmap) information so there is no "real" surface normal, thats why i use this technique, at least for raster graphics,

    another way to go about it is to make certain objects (flat rectangle detectors) and set a value to the angle of that object, then you place those all over the surface of the terrain (whatever it is, and manually rotate them for each surface, making sure you leave a bit portruding so it can "catch" objects, it takes more time, but it works alot better. u then set the sprites angle or wtv u need to the current detector its colliding with

    hope this helped

  • you must also not that in order to find normals you need vector graphics, raster graphics have no information on there faces vertexes and edges are non existant, they are just pixel or no pixel (bitmap) information so there is no "real" surface normal, thats why i use this technique, at least for raster graphics,

    Yeah this is the trouble, it means instead of just being able to do it really nice you gotta attempt to hack an approximation

    another way to go about it is to make certain objects (flat rectangle detectors) and set a value to the angle of that object, then you place those all over the surface of the terrain (whatever it is, and manually rotate them for each surface, making sure you leave a bit portruding so it can "catch" objects, it takes more time, but it works alot better. u then set the sprites angle or wtv u need to the current detector its colliding with

    you mean have a fake wall graphic and surround it on each edge with ones with a set normal value? I'd rather attempt a solution that'll do it for any wall, if for nothing else, for ease of level design

    I'll give the other method a shot, see what happens

  • well, u could also just give each of your level tiles a set normal, and use that, but youd need to make your terrain out of objects like those found in super mario world, i mean, have modular tiles for each top side bottom side fill and corners if plan to have them, its actaully faster to use those fake wall graphics, remember its all one object and u just scale rotate within the layout editor. i dont think youll find any better way of finding the normal of raster graphics, normals are notoriously tricky to find in bitmaps. youll need to find an approximation or else you need to use vectors. also what type of game would be needing this for and why, as that is pretty important, ive only seen this needed for a super mario galxy esc game and it was pretty buggy mostly due to it being made in 32 directions, constructs infinite directions should help make it clean and pro quality

    also note that for the first method i stated in my post b4, you would use fastloops to rotate the object and stop the loops once it hits something. this means you'll get the normal very quickly, and you wont need to set change any of the terrain, once again what this is being used for is greatly important

    keep me posted as i could probably help somewhat if ur unsure of somethings that im saying, i realise im not being too clear, but i dont think its necessary as u seem to get what i mean

  • well basically its a top down game, and I want it for the walls, so you're going around and theres a wall at an odd angle, when you walk into the wall, you want it to give a normal reaction and stop all motion in that direction. so you'd have like while sprite overlaps wall -> set x+cos(normal) y+sin(normal)

    I realise there might well be a better way of doing this, everything I've tried though I've come up against this.

    was the mario galaxy thing you mentioned this? because I actually looked at this for inspiration and couldnt work out what the heck was going on

    My latest thought has been to create some objects in the wall, roughly at the collision, then push them out of the wall in your direction at the speed you came in, when they're out, can make a line between them which should be a tangent, then can find normal from that. Prob wont work though heh.

    EDIT: what if the walls are limited to be boxes? theres gotta be a way of working it out correctly from that right?

  • yea it was that, its pretty complicated to understand. btw im in sec 3 and i havnt learned sin cos tan so i dont understand SHIT about that, i know what its for roughly but i can't understand it applied to anything yet, so i generally work around it.

    i think your making this too complicated, you dont need the walls normal at all. i mean cmon its way simpler than your making, dont overthink things. why dont u just pull the object out the direction its moving into the wall, that would give exactly the same effect. just use some fastloops for your speed control and your done. why do you need normals at all? you'll naturally slip down the wall unless your walking straight into, it based on its shape.

    i know what happened to you, it happens to me all the time lol, overthinking things makes you over look the simple solutions, and simple is almost ALWAYS better.

    and dont limit yourself to boxes,unless your absolutley sure you want them, i hate games made using direct x that only use simple terrain elements or use pixelated graphics yet run at 80 fps, its a total contradiction of what your trying to achieve.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I know I am definately making it more complicated than it needs to be, I mean its a fairly simple problem, but it wont work just having it push out in the same direction it goes in, since then it won't move at all

    <img src="http://www.quotecats.com/what/argh.PNG">

    (here red is the movement of the object, green is the reaction movement I want, and blue is what should happen)

    I want it to do it accurately, dunno I can't think of a better way.

  • i still doubt you need normals like your thinking of, using 1 sided walls any polygon is possible. why dont u just make walls have a set "normal", make them 1 sided, then lets say you were moving 10y, and 10x, and player is moving into a 90degree normal as in flat with the normal facing upwards, make players Y speed counteracted based on the "normal" and he'll continue moving 10x, but 0y. youd need to define a formula based on the walls "normal", but that shouldnt be to hard to find/figue out. just test this out. then tune it. id simply work off of 4 right angled normals to find the right formula. figure out how each x/y speed is affected by them, also, why dont you just use the 8 directions movement, why have a custom movement for a top down game? its not sin to use it for something like this. im tired and dont really want to think more lol, just try to rethink things

  • This whole issue has been quite an obstacle for me too, what I've done is when the player collides with an object, it runs a loop that shoots out some point collision detectors that stop moving when they're over a solid. Then when their 'life' private variable reaches 0, they're destroyed and the player bounces of them using this equation

    (Pseudocode-ish)

    Set Xcomp to cos((2 * Angle between dectectors - Player Angle) + Player Angle) * NewSpeed

    Set Ycomp to sin((2 * Angle between dectectors - Player Angle) + Player Angle) * NewSpeed

    Right now it's a bit buggy still and still "technically" treats all obstacles as circles but it's really all i can come up with, although with the new updates to the physics engine i'm probably just going to start using it

  • It is possible to calculate an approximate normal to the surface of something. The ball behavior does this internally, and I wrote some of the code for it. However, it's complicated and I'm sure you don't need it here.

    You should probably adopt a system a bit like the 8 direction movement's engine. The algorithm works like this:

    Attempt to move in X direction

    If X direction is blocked by solid, move back to original position

    Attempt to move in Y direction

    If Y direction is blocked by solid, move back to original position

    This per-axis check means if you are blocked by something, you can still move along the unblocked axis. It might not work perfectly for all shapes and sizes of wall, but it seems to do the job for the 8 direction movement. It is also a suitable solution... the normal detection algorithm might be quite tricky in events, and is definitely overkill for something this simple.

  • To be honest I gave up on this angle fairly quickly after I realised there was no way it was going to be simple and there is obviously a better way. Didn't think to do it for per axis like that though, so thanks for that

    I'd quite like an idea of how to find this elusive angle because I find it interesting, and I've not been able to come up with anything at all.

  • I was thinking, would this be a nice thing to add for the box object? (or maybe polygon object in future?)

  • I would still certainly love to be able to find the normals though, however with the way the physics object is going there will soon be no need for me

  • The way normals can be calculated is by moving objects in a circle. If a ball, say, has collided with the edge of an arbitrarily shaped sprite, you can move the ball out by a radius (16 pixels works OK) and then collision test in a circle (say, at 4 degree intervals). By working out the average angle of the overlapping angles, you can calculate the approximate angle towards the surface, and inverting this gives you the normal.

  • Can we expect vector-based collision masks at some point? Or a polygon object? There would be a ready polygon editor with the physics behavior .

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