This demo will give a start-
http://www.jmckell.com/directionvelo.html
-McKell
Hi there..
okay: i wanted to try to make a car game...
the problem is not really the programming, i'm not much into math anymore
(a long time ago, in a galaxy far far away...)
i want that if i press the UP key it should drive UP..
and if i press LEFT OR RIGHT it should make an circle...
my script is:
global xAlt
global yAlt
global pSpr
global pAngle
on beginsprite me
pSpr = sprite(me.spritenum)
pAngle = 0
xAlt= sprite(me. spritenum).locH
yAlt= sprite(me. spritenum).locV
end
on enterframe me
--down
if keypressed (125) then
pSpr.locV = pSpr.locV + 5
end if
--up
if keypressed (126) then
pSpr.locv = pSpr.locV - 5
end if
--left
if keypressed (123) then
winkelneu()
pSpr.locH = pSpr.locH - 5
end if
--right
winkelneu()
if keypressed (124) then
pSpr.locH = pSpr.locH + 5
end if
pSpr.rotation = pAngle
end
on winkelneu
pAngle = atan(pSpr.locH-xAlt, pSpr.locV-yAlt)/PI*-180
end
and its turning around like a drunken sailor...
can anyone help me???
thanks a lot..
joergi
This demo will give a start-
http://www.jmckell.com/directionvelo.html
-McKell
Okay, i have now perfected it..
the old one had a problem:
when you have 2 cars, and you give both care the same script (only with other keys of course) the case isn't working perfect anymore...
so i changed it, and the best: its now TIME BASED, not frame based.
it means, it will works on every computer in the self speed...
property sp
property x
property y
property tCar
on beginsprite me
sp = sprite(me.spritenum)
x = sp.loch -- position bestimmen
y = sp.locv -- position bestimmen
tCar = 0
timeout ("rot").new (1, #timeOutHandler, sprite(me.spritenum))
end
on timeOutHandler me
-- Tastaturabrage
-- vorwaerts
if keypressed(126) then speed = 2
-- links
if keypressed(123) then tCar = tCar +.2
-- rechts
if keypressed(124) then tCar = tCar -.2
--set velocity, increment position
xVelo = cos(tCar) * speed
yVelo = -sin(tCar) * speed
x = x + xVelo
y = y + yVelo
--set sprite properties
sp.loch = x
sp.locv = y
sp.rotation = -tCar * 180 / pi --convert to degrees
end
ok,thanks a lot
"jmckell" <webforumsuser@macromedia.com>
??????:b5r22r$p63$1@forums.macromedia.com...