Skip to main content
Known Participant
October 16, 2023
Question

line to movieclip collision

  • October 16, 2023
  • 1 reply
  • 2307 views

Dear All Thank you for your time

I have aproblem that cant seem to work out looked on line and read some books but cant find

a solution. I have one movie clip that is tweened on a straight path that is movable with the mouuse

as wel as rotatable with buttons, the imbedde tweened object cabn also be moved with buttons . The collision object is a line that rotates 360deg with a button . That all works, what I cant figure out to do is display the distance to the line as the tweened object approaches the like a countdown to a colision.

added a photo to help explain.

Thank you all

    This topic has been closed for replies.

    1 reply

    kglad
    Community Expert
    Community Expert
    October 16, 2023

    you can get an exact answer for a disc/circle and an approximation for a square using:

     

    first, calculate the line segment's point of collision.

    then, calculate distance between your object's center of that point of collision

     

    if you need a more exact answer, you would need both collision points, the segment and the object.

    Known Participant
    October 17, 2023

    Dear Kglad

    Thank you for your reply

    I am not sure how acomplish to that, as both the object and the ray are on different time lines how and are both capable of moving to diffent places on the screen. I can work it out if static but not each a time a new ray position and a new path is chosen.

    Thank you peter

     

     

    Known Participant
    October 22, 2023

    i don't think i can answer that without checking your fla and this problem is non-trivial. ie, it would take me more than 1 hour (i think) to solve for you.


    Dear Kglad 

    I have done some researching and have come up with a solution by adapting  a JS code online to animate for most of my problems ,the only sticking point now is cant get the movie clip on stage and the create guided path does not seem to work for the created circle. The movie clip in the library wil alsol not allow me to give it a linkage name (Adobe animate 2023) .The motion guide can work if put static numbers but not it seems with variables.Would like to post FLA but seems to be no way to do that.

     

    Red point, is point of intercection

    purple is object to place on path.

     

    Best Regards

    Peter

     

     

    createjs.Ticker.addEventListener("tick", tick);
    createjs.MotionGuidePlugin.install();
    var p = this.yellowmc.dot1.localToGlobal(0,0);//dot and other end of the line
    var q = this.greenmc.dot1.localToGlobal(0,0);// dot at other end of the line
    
    var x2 = p.x
    var y2 = p.y
    var x4 = q.x
    var y4 = q.y
    
    var Ax = this.yellowmc.x //yellow line on the stage
    var Ay = this.yellowmc.y //green line on the stage
    var Bx = p.x
    var By = p.y
    
    var Cx = this.greenmc.x
    var Cy = this.greenmc.y
    var Dx = q.x
    var Dy = q.y
    
     var top = (Dx-Cx)*(Ay-Cy)- (Dy-Cy)*(Ax-Cx)
     var bottom =(Dy-Cy)*(Bx-Ax)- (Dx-Cx)*(By-Ay)
     console.log (top+("Top"))
    
     var t = top/bottom
     console.log(t,"T")
     var w =Ax + (Bx-Ax)*t
    	 console.log (w)
    
    	 var s =Ay + (By-Ay)*t
    	 console.log (s) 
    function newdot(A,B){
    	
    var dot = new createjs.Shape();
    	stage.addChild(dot);
    dot.graphics.beginFill("red").drawCircle(A,B, 20);
    
    }
    newdot(w,s)
    newdot(Ax,Ay)
    newdot(Bx,By)
    var text = new createjs.Text("A", "20px Arial", "black");
     text.x = Bx
     text.y = By
     this.addChild(text);
     function createline(a,b,c,d){
    var line = new createjs.Shape(line);
    
                
                stage.addChild(line);
                line.graphics.setStrokeStyle(1).beginStroke("#000000");
                line.graphics.moveTo(a,b);
                line.graphics.lineTo(c,d);
                line.graphics.endStroke();
                stage.update();
    
     }
    createline(Ax,Ay,Bx,By)
    createline(Cx,Cy,Dx,Dy)
    
    
    var shape = new createjs.Shape();
    shape.graphics.beginFill("#ff00ff").drawCircle(Ax,Ay,50);
    stage.addChild(shape);
    
    //createjs.Tween.get(shape).to({guide:{ path:[0,0,w,s,Bx,By] }},7000);
    
    //Cant get tween to work
    function tick(event) {
        stage.update();
    }
    this.addChild(new lib.mybox())// does not work