Normal angle of a sprite at different positions

For questions about using Classic.

Post » Sat Sep 06, 2008 9:28 pm

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:

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).
B
2
S
2
G
5
Posts: 236
Reputation: 2,122

Post » Sat Sep 06, 2008 10:24 pm

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
B
52
S
7
G
6
Posts: 1,945
Reputation: 7,610

Post » Sat Sep 06, 2008 10:34 pm

[quote="QuaziGNRLnose":3vyvxd76] 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,[/quote:3vyvxd76]
Yeah this is the trouble, it means instead of just being able to do it really nice you gotta attempt to hack an approximation :|

[quote="QuaziGNRLnose":3vyvxd76]
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
[/quote:3vyvxd76]
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
B
2
S
2
G
5
Posts: 236
Reputation: 2,122

Post » Sat Sep 06, 2008 10:58 pm

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
B
52
S
7
G
6
Posts: 1,945
Reputation: 7,610

Post » Sat Sep 06, 2008 11:18 pm

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?
B
2
S
2
G
5
Posts: 236
Reputation: 2,122

Post » Sat Sep 06, 2008 11:46 pm

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.
B
52
S
7
G
6
Posts: 1,945
Reputation: 7,610

Post » Sat Sep 06, 2008 11:58 pm

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

(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.
B
2
S
2
G
5
Posts: 236
Reputation: 2,122

Post » Sun Sep 07, 2008 12:09 am

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
B
52
S
7
G
6
Posts: 1,945
Reputation: 7,610

Post » Sun Sep 07, 2008 5:28 am

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
B
3
S
2
G
5
Posts: 351
Reputation: 2,377

Post » Sun Sep 07, 2008 4:11 pm

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.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests