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 3631664
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:25:35+00:00 2026-05-19T00:25:35+00:00

I’m currently developing a script for a map in COD4. I think that the

  • 0

I’m currently developing a script for a map in COD4. I think that the language is so simple that I’m tagging this as language-agnostic since the problem is in the algorithm for this situation.

There is a room which is 960 units wide. And inside it there’s an object in the middle, which we’ll count as the axis. The ball is supposed to move to a random position each time it is hit, but should not traverse further than the walls. Here’s a diagram:

Image

The API of the game only allows the moving of objects relative to its position, as far as I know, so here’s code that I came up with. The problem is that after the second call to head_move() it begins to produce unexpected results and this is crashing my head. Could somebody help me out?

movementThink():

while (1)
{
    self waittill ("trigger", player); //Wait till player hits the object       
    head_origin thread head_move();

}



head_move()
{
    /* level.prevx is a global variable which I use to store
    the distance traveled in the previous shot. Defaults to 0 */

    /*This works in the first and second hit, but then it begins to show
    incorrect max and min values*/

    x_min = (0-480) + level.prevx;
    x_max = x_min + 960;

    x_units =  RandomIntRange( x_min, x_max ); //Create a random integrer

    log2screen("MIN: " + x_min + " and MAX: " + x_max + " and MOVED " + x_units);
    log2screen("Moved " + x_units);

    //Movement function, first parameter is the distance to be traveled, and the second one is the speed
    self movex (x_units , level.movespeed); 

    level.prevx = x_units;

}

EDIT: Just to clarify. When the user shoots the ball, its position changes to a certain value. Now, if he hits it again, the min and max values of the random int generator should change to prevent the ball from moving outside the walls. Example:

  1. Level starts. The ball is in the middle of the room. The min and max ranges are -480 and 480 respectively
  2. The user hits the ball and its moved -200 units (200 units to the left).
  3. Now, the min and max range should be -280 and 680.

I hope this is clear enough.

EDIT 2: Edited the sign as FlipScript suggested. Here’s the output from the log2screen functions, what is actually happening:

  1. MIN: -480 and MAX 480. MOVED 67
  2. MIN: -413 and MAX 547. MOVED 236
  3. MIN: -244 and MAX 716. MOVED 461

Just a sample case. Something is backwards I believe, these aren’t the right calculations to do.

  • 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-19T00:25:35+00:00Added an answer on May 19, 2026 at 12:25 am

    Your code works only when self.prevx contains your displacement from the starting position, i.e. your absolute position. However, what you are storing is your displacement from your current position. It works the first two times because that displacement happens to be the same as your absolute position, but once you move again, you lose all track of where you are.

    What you should do instead is get rid of min and max, and start by calculating a random absolute position within the bounds. Then use your previously stored absolute position to calculate the relative movement needed to get you there, and store the new absolute position.

    head_move()
    {    
        new_x = RandomIntRange( -480, 480 ); //create a random location
    
        delta_x = new_x - level.prev;  //determine relative movement needed to get there
    
        self movex (delta_x , level.movespeed); //move to new position
    
        level.prevx = new_x;  //store new position
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
I want use html5's new tag to play a wav file (currently only supported
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a JSP page retrieving data and when single or double quotes are
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.