forums

TNT Basic Forums > Programming Q&A
running into walls
< Last Thread     Next Thread >
Author
Thread        Post A Reply

01-02-2004 21:01

Posted by:
madscientist

Location:
n.ireland

Click Here to Email madscientist   Find more posts by madscientist

im having a bit of difficulty working out an algorithm to control a person running into a wall or any given obstacle.

the movement is controlled by using the algorithm
(direction being between 0 and 360)
xvel= (sin (direction)) *speed
yvel= (cos (direction)) *speed
playerx=playerx-xvel
playery=playery+yvel
sprite 1,playerx,playery,001

when you hit the edge of the map its quite easy to move it back
if playerx<300 then playerx=300
if playery<400 then playerx=401
which works because its a rectangle and you can only hit it from one direction.

but when you have something of shape X, how do you tell what side youve hit and which direction you need to move away?

01-03-2004 00:11

Posted by:
fjerkon

Location:
Sweden

Find more posts by fjerkon

i guess you use some kind of angle-calculation. say you hit the 'stone', or whatever, from angle 241 you have to move the character back in the same angle.... is this what you're talking about or am i totally off?

01-03-2004 00:15

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

It depends how you define the shape. It would probably be a lot easier to do it graphically, like with a collision image, but you might be able to use an algebraic equation too. If you only use certain angles you might be able to use a TNT map and check the tile for the angle. For example, you might have a tile with a wall at 45 degrees, a wall at 135 degrees, etc. Then you would know which direction the wall came from.

01-03-2004 01:49

Posted by:
-wyvern

Location:
Bedroom

Find more posts by -wyvern

One thing you can do is set up a series of "sensors", ie a small assortment of sprites that follow your character, but are invisible. Instead of testing your player, you test the sensor sprite. You have one to the left and right at waist hight for walls, another one on the feet for drops etc. The clever part comes when you have a vertical line of these sensors either side of the feet to detect where the floor is. On level ground both of the lowest ones will touch, but none of the others. On the edge of a cliff, only one will touch, and your character can teeter amusingly on the edge of destuction awaiting only a sufficiently strong sneeze to send him to his doom (I love designing levels... ah.) Finally on a slope two on one side will be overlapping backdrop and you can angle the feet accordingly. The principal remans the same with many situations in many kinds of game, and it needs no complex maths, just a good memory, or lots of rem statements. The latter in my case... Have fun.

-wyvern

01-06-2004 22:55

Posted by:
madscientist

Location:
n.ireland

Click Here to Email madscientist   Find more posts by madscientist

invisible sprites?

ok, ill buy the last one, it sounds fun.
one thing though-how do you make them invisible? it would kind of ruin the effect having random dots floating about......

01-06-2004 23:36

Posted by:
MapMaker

Location:
Edmonton, Alberta (Canada)

Click Here to Email MapMaker   Find more posts by MapMaker

set sprite transparency x,100

01-07-2004 21:18

Posted by:
puffin

Click Here to Email puffin   Find more posts by puffin

forget it

forget angle calculation, i'd imagine it would be hard as hell and probably not worth the effort. is what you should do is just make things bounce. when an object hits another object and it is traveling along the x-axis you need to multiply the variable you use to control the x speed by -1. this will switch it's direction. you can build on this and make the effect of the bounce decrees over time.

if your dead set on accuracy though, i think vector algebra is your ticket. but if your trying to do that i still think you won't be able to use sprites because they're always rectangular, like windows. you could only use drawing routines. so you have the choice between faster, pretty, but less accurate and slower, uglier, and negligibly more accurate.

01-07-2004 21:23

Posted by:
puffin

Click Here to Email puffin   Find more posts by puffin

maybe i was exagerating your problem. if you just want to make somthing bounce like the ball in pong go to my post titled "bounce".

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.