I'm new to this king of logic. I want to create an object (Mc) that can move alone inside a defined area. Like a bug in my screen. This is to create a small game. Any idea or tutorial or... Tanx in advanced
Humm When it comes near of a border it can change direction. I want to learn how to program some king of movement. I know there is Math.sin, Math.cos and other but how to use it? It's a general question. Nothing specific. Just want to learn more in this king of programmation. It's different of building an application. It's like Artificial Intelligence.
you'll need to initiate a loop. setInterval() is an easy way to do that. you'll need to define your bug's speed and initial direction of travel. here's an example of a bug moving within (roughly) a rectangle: speed = 5; dir = Math.PI-2*Math.random()*Math.PI; moveI = setInterval(moveF, 80); function moveF() { if (bugMC._x+speed*Math.cos(dir)+bugMC._width>400) { dir = (2*Math.round(Math.random())-1)*Math.PI/2+Math.random()*Math.PI/2; } if (bugMC._x+speed*Math.cos(dir)<200) { dir = -Math.PI/2+Math.random()*Math.PI; } if (bugMC._y+speed*Math.sin(dir)+bugMC._height>400) { dir = -Math.random()*Math.PI; } if (bugMC._y+speed*Math.sin(dir)<200) { dir = Math.random()*Math.PI; } bugMC._x += speed*Math.cos(dir); bugMC._y += speed*Math.sin(dir); bugMC._rotation = 180*dir/Math.PI; }
Thats cool. It's something like that I want. Is there some tutorial or code that makes an object (MC) following a curved line (guide). The clip follows this line, when it arrived at the final point, a new line is create as a guide for the clip. In that way the clip could move smoothly.
if you can define your curve (with parameters, for example), you can use actionscript to move your bug. however, if you cannot define the curve you must use a motion guide. i'm not sure what you mean, by "...that way the clip could move smoothly." in what way does the code i suggested fail to do what you want?
Don't see what you're looking for? Try a search.
|