Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

AttachTo() disables movement of the car

Hi everybody, I hope you could help me out with this, I'm new to the Unreal Engine.

I'm working with the Vehicle template project that comes UE 4 (not the advanced one, and using C++ not Blueprint). I have to work in code only, due to what my supervisor tells me, so no BP. I want to add a collision box to the front of the car that extends 1000 units forward in order to "scan" the area in front of the car for objects it can collide with. Later I intend to measure the distance between the car and the different objects infront of it. I have added the following code att the end of the constructor ASimpleCarPawn::ASimpleCarPawn()

 CollisionScan = CreateDefaultSubobject<UBoxComponent>(TEXT("CollisionScan"));
 CollisionScan->SetBoxExtent(FVector(1000.f, 90.f, 70.f));
 CollisionScan->SetRelativeLocation(FVector(1200.f, 0.f, 100.f));

The problem is that now the car doesn't move any more, the gear is shifting though, so the code seems to be working, except that the car is not moving. If I however remove the last line CollisionScan->AttachTo(GetMesh()); the car can run as it should, however now the collision box i fixed in the world and does not follow the car around and also its position is not correct in relation to the car, as if the SetRelativeLocation is now using the world as a base point rather then the car itself. To clearify, when i do have the CollisionScan->AttachTo(GetMesh()); code in there, the position of the collision box in relation to the car is correct, but as I said, now the car does not move.

What am I doing wrong? How can I fix this? Thanks for your time! /Kristoffer

Product Version: UE 4.8
more ▼

asked Jun 17 '15 at 03:21 PM in C++ Programming

avatar image

Kristoffer Helander
22 9 11 15

avatar image Kristoffer Helander Jun 18 '15 at 09:06 AM

I looked at the C++ video tutorials and in that a collision sphere is added to the 3rd person character in a similar way, but with CollisionScan->AttachTo(RootComponent); instead. However that doesn't work for me, the car still can't move forward.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Try to get a look at the CollisionScan's mesh properties: maybe it's set to blockAll, thus blocking the movements and/or keeping the car slightly up in the air.

more ▼

answered Jun 18 '15 at 02:37 PM

avatar image

391 17 12 32

avatar image Kristoffer Helander Jun 22 '15 at 08:40 AM

Yes, thank you! That was the thing. Funny, though, since when I did the same thing in the Code Tutorial from Epic, it worked straight up, without any changes needed. But anyway, it works now. Thank you!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question