Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7057389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:58:48+00:00 2026-05-28T03:58:48+00:00

I do not find what’s the problem. I am using ccpToAngle() to find an

  • 0

I do not find what’s the problem. I am using ccpToAngle() to find an angle of vector but can’t get proper angle. My ball is launched/initial position at cpp(170,40) and using swipe i want to throw it.
I wrote to find an angle,

 -(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event {

    CGPoint location = [touch locationInView: [touch view]];
    CGPoint vector = ccpSub(location, ccp(170 ,40));
    normalVector = ccpNormalize(vector);
    float angleRads = ccpToAngle(normalVector);
    float angle = CC_RADIANS_TO_DEGREES(angleRads);
   }

but here if i swiped more then angle is increased. I think, swipe in same line/direction the angle should be same every time. but here, I am getting angle between 70 to 90 degrees only, if swipe more then angle is near to 60,66 degrees.

I want angle between 0 to 180 degrees. is it possible that it can consider ccp(170 ,40) as axis origin & find an angle of vector in Cocos2d?

Thanks In advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:58:49+00:00Added an answer on May 28, 2026 at 3:58 am

    if you want to find an angle of swipe you have to use trigonometry here..

    Here is some that can help you..

    - ( void ) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        UITouch *touch = [touches anyObject];
       locationTouchBegan = [touch locationInView: [touch view]];
        //location is The Point Where The User Touched
        locationTouchBegan = [[CCDirector sharedDirector] convertToGL:locationTouchBegan];
        //Detect the Touch On Ball
        if(CGRectContainsPoint([ball boundingBox], locationTouchBegan))
        {
            isBallTouched=YES;
        } 
    
    }
    

    this how you detect that ball is touched

    Now on touch end we can calculate the direction.

    - ( void ) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
        UITouch *touch = [touches anyObject];
       locationTouchEnded = [touch locationInView: [touch view]];
        locationTouchEnded = [[CCDirector sharedDirector] convertToGL:locationTouchEnded];
        [self calculateDirections];
    }
    

    this is how we calculate direction.

    -(void)calculateDirections
    {
        if (isBallTouched==YES )
        {
            perpendicularBig = screenSize.height - ball.position.x;
            baseSmall = screenSize.width/2 - locationTouchEnded.x; // if the ball is at center.
            perpendicularSmall=locationTouchEnded.y - ball.position.x;
            baseBig=(perpendicularBig*baseSmall)/perpendicularSmall;
            endPoint=ccp(screenSize.width/2 - baseBig,320); //320 can replace by the value of end point y where you want to end the ball run. 
            [self moveBall:3.0f];
        }
    }
    -(void)moveBall:(float)duration
    {
    
        [ball runAction:[CCJumpTo actionWithDuration:duration position:ccp(endPoint.x,endPoint.y) height:20 jumps:1]];
        isBallTouched = NO;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

actually I can not find an exact title for this problem. But I can
I've researched this issue and can not find a solution. My problem is that
I can not find how to implement a design in C++. In the language
I searched a lot but could not find a way to dump table relations
I have Googled merge+cell+Javascript but did not find any suitable code to implement merge
can not find this option in new studio (2010)
it seems i can not find what i am looking for anywhere. i am
Sorry I could not find the appropriate title Here is my problem I am
Can not find a command that displays the current configuration of mysql from within
Searching did not find a similar question, so: How can POST data used by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.