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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:43:32+00:00 2026-05-27T10:43:32+00:00

This is a basic AI script, where the function AttackPlayer should only happen once.

  • 0

This is a basic AI script, where the function AttackPlayer should only happen once. The attack is a jump, but instead of one time, it gets called 12 times before the “Attacking Denied” message pops up, which results in a massive horizontal boost.

What am I doing wrong?

var player : GameObject; 
var speed : float=6f; 
var range : float=15f;
var hitRange : float=6f;
var rotationSpeed : float=5f;
var delta : Vector3;
var distance;
var jumpForce : float = 8.0;
var airModifier : float = 20.0;

var test : float = 0;

private var horMovement : Vector3 = Vector3.zero;
private var forwardMovement : Vector3 = Vector3.zero;
private var jumping : boolean = false;
private var grounded : boolean = true;


function Start()
{
    player = GameObject.FindGameObjectWithTag("Player");
}

function FixedUpdate()
{
    distance = Vector3.Distance(transform.position, player.transform.position);
    if(distance<=range){   
        MoveTowards();
        RotateTowards();
        AttackPlayer();
    }
}

function MoveTowards()
{
    //are we grounded?
        if (Physics.Raycast(transform.position, -transform.up, 2)) {
            grounded = true;
        } else {
            horMovement *= airModifier;
            forwardMovement *= airModifier;
            grounded = false;
        }
    delta = player.transform.position - transform.position;
    delta.Normalize();
    delta.y = 0;
    var moveSpeed = speed * Time.deltaTime;
    transform.position = transform.position + (delta * moveSpeed);
}

function RotateTowards()
{
    transform.rotation = Quaternion.RotateTowards (transform.rotation, Quaternion.LookRotation(delta), rotationSpeed);
    transform.rotation = Quaternion.Euler(0, transform.eulerAngles.y, 0);
}

function AttackPlayer()
{
    if (!(grounded)){
    print("Attacking Denied");
    return;
    }

    if(distance<=(hitRange) && (grounded) && !(jumping)){
        rigidbody.AddRelativeForce(transform.up * jumpForce, ForceMode.Impulse); 
        Jumping = true;
        test += 1;
        print(test);
    }
}
  • 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-27T10:43:32+00:00Added an answer on May 27, 2026 at 10:43 am

    In that last if block, the Jumping = true; should be jumping = true;.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I feel like this should work: $(.module .one).hover(function() { $(#one).addClass('red'); }); Basically I am
Forgive my ignorance in asking this basic question but I've become so used to
I'm trying to learn this basic thing about processors that should be taught in
This is basic stuff, but I'm somewhat unfamiliar with VBA and the Word/Access object
This is very basic stuff , but here goes. I find that I am
This might be basic question but how do I create a list of lists
I have the following basic function: <script type=text/javascript> function Form_Data(theForm) { var t=1; while
Only just starting out with jQuery and I'm sure this is basic stuff for
Maybe this is very basic, but I am all confused. I have a simple
So I have this basic script: /*check if email is valid*/ if (substr_compare (

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.